Skip to content

Track dynamic fixture dependencies#14288

Open
Anton3 wants to merge 2 commits intopytest-dev:mainfrom
Anton3:setuponly-parametrized-output
Open

Track dynamic fixture dependencies#14288
Anton3 wants to merge 2 commits intopytest-dev:mainfrom
Anton3:setuponly-parametrized-output

Conversation

@Anton3
Copy link
Contributor

@Anton3 Anton3 commented Mar 14, 2026

This PR adds FixtureRequest._own_fixture_defs and uses it for a more accurate --setuponly and --setupshow output. This might be a bit overkill for this specific purpose, but _own_fixture_defs can also be used to track fixture dependencies for proper teardown in case of parametrized fixtures, see PR #14104.

Fixes: #14287

This PR adds `FixtureRequest._own_fixture_defs` and uses it for a more accurate `--setuponly` and `--setupshow` output. This might be a bit overkill for this specific purpose, but `_own_fixture_defs` can also be used to track fixture dependencies for proper teardown in case of parametrized fixtures, see PR pytest-dev#14104.

Fixes: pytest-dev#14287
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Mar 14, 2026
@Anton3 Anton3 marked this pull request as ready for review March 14, 2026 12:03
@Anton3
Copy link
Contributor Author

Anton3 commented Mar 14, 2026

@bluetech @RonnyPfannschmidt I've taken a slice of #14104

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

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

Thanks for splitting this.

I think that only for the benefit of setuponly it is hard to justify the extra complexity added by _own_fixture_defs to the fixture core. Since I can't approve this PR on its merit alone, I'll go over to #14104 to try and see the larger motivation.

Comment on lines +380 to +381
# The argnames evaluated in the current test item, mapping to the FixtureDef
# they resolved to.
Copy link
Member

Choose a reason for hiding this comment

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

"in the current test item" is a good addition, but let's keep the "so far" to make it clear it's a mutable dict that is filled as fixtures are evaluated.

Suggested change
# The argnames evaluated in the current test item, mapping to the FixtureDef
# they resolved to.
# The argnames evaluated in the current test item so far, mapping to the FixtureDef
# they resolved to. Shared by the TopRequest and all of its SubRequests.

@@ -377,9 +377,12 @@ def __init__(
# collection. Dynamically requested fixtures (using
# `request.getfixturevalue("foo")`) are added dynamically.
self._arg2fixturedefs: Final = arg2fixturedefs
Copy link
Member

Choose a reason for hiding this comment

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

Reviewing this inspired me to do a cleanup here: #14290

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.

Dynamic fixture dependencies are not shown in setuponly and setupshow

2 participants