Skip to content

Conversation

gomri15
Copy link

@gomri15 gomri15 commented Sep 18, 2025

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

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 18, 2025
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Thanks @gomri15 for the PR!

Left some small suggestions, please take a look.

@gomri15
Copy link
Author

gomri15 commented Sep 27, 2025

@nicoddemus You guys squash all the changes or leave them?, i assumed squash but want to make sure.

@gomri15 gomri15 requested a review from nicoddemus September 27, 2025 17:33
@gomri15 gomri15 force-pushed the fix-exit-exceptiongroup-13650 branch from aeec7d8 to e56af36 Compare September 27, 2025 17:41
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.

pytest.exit() not working when in ExceptionGroup
2 participants