Skip to content

Use the obj passed to Class.from_parent - #15247

Open
LuanaPBueno wants to merge 1 commit into
pytest-dev:mainfrom
LuanaPBueno:fix-class-from-parent-obj
Open

LuanaPBueno wants to merge 1 commit into
pytest-dev:mainfrom
LuanaPBueno:fix-class-from-parent-obj

Conversation

@LuanaPBueno

@LuanaPBueno LuanaPBueno commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Class.from_parent() accepted an obj argument but ignored it, so the class was always looked up again on the parent by name (pytest_pycollect_makeitem even passes obj=obj there). Now the given obj is used, and class marks still work because it goes through _getobj(). I used Claude to help, and reviewed and tested the changes myself.

This overlaps with pytest-dev/pytest#14809, which contains the same fix (an accidental recreation). Once this is merged, the corresponding hunk can be dropped from pytest-dev/pytest#14809.

Closes #7063

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Add text like closes #XYZW to the PR description and/or commits.
  • If AI agents were used, they are credited in Co-authored-by commit trailers.
  • Create a new changelog file in the changelog directory.
  • Add yourself to AUTHORS in alphabetical order (I did this in pytest-dev/pytest#15202 (already merged), so my name is already in the list).

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 22, 2026

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

Thanks, the change itself looks correct: the new test fails on main and passes here, and going through _getobj() keeps class marks working. Two small things before merging:

  1. The checklist ticks "Add yourself to AUTHORS", but AUTHORS is not changed in this PR. Please add yourself.
  2. The commit trailer Co-authored-by: Claude has no email, so GitHub does not recognize it as a co-author. The usual form is Co-authored-by: Claude <noreply@anthropic.com>.

Note: this looks like an accidental recreation of a change I already had in my draft #14809 (the ensemble PoC), where Claude made the same fix while I was working on it: the same _given_obj attribute, the same from_parent/_getobj override, and a test that also uses name="NotAnAttribute", obj=... (testing/test_ensemble.py there). That's fine, splitting it out of a large draft is useful. Please mention #14809 in the PR description so the two stay linked, and I'll drop the hunk from #14809 once this is merged.


Generated by Claude Code

@LuanaPBueno

Copy link
Copy Markdown
Contributor Author

Hi, about de authors, I didn't actually put my name in this PR as author because Im already in the list (you just merged another Pull Request of mine), but I put as check because I put my name in the authors list in the other PR

Closes pytest-dev#7063

Co-authored-by: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix support for obj parameter of Class.from_parent

2 participants