runner: re-raise pytest.exit inside ExceptionGroups (fixes #13650) #13736
+52
−3
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.
Fix issue: 13650, fixes regression when adding exception group which meant pytest raises in teardown wouldn't stop execution
Scope note: This PR intentionally does not handle nested ExceptionGroups (EGs containing EGs). That can be discussed in a follow-up if desired.
Handle pytest.exit() in exception group by searching in exception group if pytest.exit() found and reraising it.
Rationale:
Before Python 3.11 (no EGs), CallInfo.from_call re-raised certain exceptions (e.g., Exit, KeyboardInterrupt) so they bypassed reporting. With EGs, those exceptions could be inside a group, and the simple isinstance(excinfo.value, reraise) check no longer triggered. The session would continue to the next test instead of stopping. This PR restores the original contract in an EG world, without introducing new flows or flags.
Fixes #13650