Fix stale fixture finalizers after setup errors - #14970
Open
MarthalaJagruthiReddy wants to merge 1 commit into
Open
Fix stale fixture finalizers after setup errors#14970MarthalaJagruthiReddy wants to merge 1 commit into
MarthalaJagruthiReddy wants to merge 1 commit into
Conversation
MarthalaJagruthiReddy
force-pushed
the
fix/fixture-finalizer-after-setup-error
branch
from
September 4, 2026 21:51
b9871ae to
9f249a6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a
pytest_fixture_setuphook raises while setting up a parametrized fixture,FixtureDef.finish()returned early becausecached_resultwasNone. The post-finalizer remained queued, so the next parameter hit theassert not self._finalizersassertion and failed internally.The same stale-finalizer state occurs with pytest's built-in async-fixture guard, where one unsupported async fixture can turn later tests into bare internal errors. Keep the early return only when there are no pending finalizers. This allows pending cleanup to run after setup failures and lets subsequent tests report their own results.
Fixes #14800
Tests
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 uv run --frozen pytest -o minversion=0 testing/python/fixtures.py -q(241 passed, 3 xfailed)PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 uv run --frozen pytest -o minversion=0 testing/acceptance_test.py -k 'sync_test_async_fixture or async_autouse_fixture' -q(4 passed)uvx ruff check src/_pytest/fixtures.py testing/python/fixtures.py testing/acceptance_test.pyuvx ruff format --check src/_pytest/fixtures.py testing/python/fixtures.py testing/acceptance_test.pyChecklist
changelog/.AUTHORS.Co-authored-bycommit trailers.