pytest icon indicating copy to clipboard operation
pytest copied to clipboard

runner: re-raise pytest.exit inside ExceptionGroups (fixes #13650)

Open gomri15 opened this issue 2 months ago • 7 comments

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

gomri15 avatar Sep 18 '25 13:09 gomri15