pytest.exit() not working when in ExceptionGroup #13650
Description
Activity
- addedtype: bugproblem that needs to be addressedproblem that needs to be addressedneeds backportapplied to PRs, indicates that it should be ported to the current bug-fix branchapplied to PRs, indicates that it should be ported to the current bug-fix branch
on Aug 14, 2025 nice find - this was most likely a oversight when teardown got migrated from plain exceptions to exceptiongroup
Also see #13537 which is mostly the same issue, but for skipping.
Reacted by mtrzm@RonnyPfannschmidt Do you need help to backport this?
Huh? There's nothing to backport as long as there's no fix, and most backports are automated.
Ohh.. Newbie here. I was not aware about this. I thought the "needs backport" meant help was needed to backport this.
@RonnyPfannschmidt is this something i can take a shot at fixing ?. or due to the complexity of the issue and my lack of knowledge of the code base it's better left to someone more experienced?
I haven't assessed complexity
The problem naively reads as handle exceotion groups in some places
So its definitely a neat way to learn the codebase abd figure if the naive reading is good enough
i would love to give this my best shot if, could you assign me to it please.
and if you can point me to anywhere in the code base i should start i would really appreciate it. thank you.
The starting point would be to turn the failing examples into acceptance tests in a fitting place tgen following the traceback of those errors
Thanks so much for the guidance, excited to start working on this
Submitted a small fix, note it doesn't handle nested exception groups I thought it would over complicate the code for A unlikely edge case.
if you think otherwise i can add support and tests for it,
Hi there, my team and i would like to work on this issue if that is alright with you?
Hi there, my team and i would like to work on this issue if that is alright with you?
There is already a PR waiting for rereview on this :)
Any chance of getting a review for this?.
Apologizes if it's forward of me to ask, this is my first time attempting to contribute to open-source code and I am not sure what the etiquette or expected timeline is for a review.Please take no offence in my forwardness and see it as excitement to contribute and help make this great repo a little bit better.
I can see 3 possible semantics for this (an exception group which contains an exception that should be re-raised):
- If the EG contains a re-raise E, then re-raise the first one (this is what @gomri15 currently implemented)
- If the EG contains a re-raise E, then re-raise the entire EG
- If the EG contains more than one re-raise E, then re-raise them all in an EG
Since the re-raise exceptions in pytest itself are stuff like
Exit,KeyboardInterrupt,SystemExit, I feel pretty good about choice 1. Usually they'll just kill the session so there's no need to preserve anything beyond the first one.I searched for
reraiseandCallInfo.from_callin my "plugin corpus" and didn't find any different uses.So unless anyone thinks different I think we can merge PR #13736.
Hi
I have a situation where I have two teardown fixtures:
pytest.exit()- I use it to stop testing session when only specific test fails.Simplified example:
My expectation is that:
test_1passestest_2call passes, teardown reports error (due to exception infailing_teardown) and test session finishes due topytest.exit()inexit_sessionfixturetest_3is not executedBut the exception from _pytest.outcomes.Exit is only logged inside ExceptionGroup and exit is not performed:
If I remove
failing_teardownfixture,pytest.exit()works:log:
Environment: