Repository navigation
Conversation
Collect exception groups alongside ordinary teardown outcomes so remaining finalizers release their owners before the error is re-raised. Keep direct control-flow exception behavior unchanged. Co-authored-by: OpenAI Codex <noreply@openai.com>
This branch has not been deployed
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.
Related work: #15330 addresses the same issue and was discovered during the final duplicate check. This is an independently prepared alternative, opened as a draft to make the overlap explicit rather than request duplicate review. The additional regression coverage checks GeneratorExit, finalization at module scope, preservation of the original exception object, and both fixture-owner release events in a subprocess. I am happy for maintainers to prefer #15330 or reuse any useful tests; this PR does not claim exclusive ownership of the fix.
A finalizer raising a
BaseExceptionGroupcontainingCancelledErrororGeneratorExitescapesSetupState.teardown_exactbefore the remaining finalizers run. A dependent function-scoped fixture can retain its cached value and be reused by the following test.Include
BaseExceptionGroupalongside the existing teardown outcomes so remaining finalizers run before the collected error is re-raised. Direct, ungrouped control-flow exceptions retain their existing behavior.Refs #15329.
Validation on Python 3.12.15 / macOS:
python -m pytest testing/test_runner.py testing/python/fixtures.py -q: 316 passed, 4 xfailed, 2 deprecation warnings.pre-commit run --files src/_pytest/runner.py testing/test_runner.py AUTHORS changelog/15329.bugfix.rst: all applicable checks passed.AI assistance: OpenAI Codex helped investigate the issue, prepare this patch and run validation. The author reviewed the patch and accompanying explanation and authorized this submission.