Skip to content

fixtures: deprecate calling request.getfixturevalue() during teardown#14295

Open
bluetech wants to merge 2 commits intopytest-dev:mainfrom
bluetech:deprecate-getfixturevalue-teardown
Open

fixtures: deprecate calling request.getfixturevalue() during teardown#14295
bluetech wants to merge 2 commits intopytest-dev:mainfrom
bluetech:deprecate-getfixturevalue-teardown

Conversation

@bluetech
Copy link
Member

on a fixture that hasn't already been requested.

Fix #12882.

The first commit is needed for the $subject change.

…ssage

In this case let's just show the test function.
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Mar 16, 2026
Copy link

@themavik themavik left a comment

Choose a reason for hiding this comment

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

Deprecates calling request.getfixturevalue() during teardown for fixtures not already requested. Addresses #12882.

Done well: Clear deprecation docs explaining why (teardown runs during scope unwind, lookup order is brittle). Good test coverage: previously-requested OK, new fixture warns, inactive fixture errors. is_node_active is a clean abstraction. _raise_teardown_lookup_error gives a helpful message.

Concern: In formatrepr, the change from assert self.msg is None or self.fixturestack to if msg is not None and len(stack) > 1 removes the assert. The old assert guarded against empty fixturestack with non-None msg. The new logic avoids the crash by not using stack[:-1] when len(stack) <= 1. Worth a quick check that no code path can hit msg is not None with empty fixturestack—if so, the formatrepr output might be odd. Otherwise looks good.

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.

Confusing AssertionError when using request.getfixturevalue with new fixture during teardown

4 participants