Skip to content

Fix fixture teardown after BaseExceptionGroup - #15431

Open
rraghav01 wants to merge 1 commit into
pytest-dev:mainfrom
rraghav01:fix/15329-continue-fixture-teardown
Open

rraghav01 wants to merge 1 commit into
pytest-dev:mainfrom
rraghav01:fix/15329-continue-fixture-teardown

Conversation

@rraghav01

Copy link
Copy Markdown

Summary

  • Continue running fixture finalizers after a BaseExceptionGroup is raised during teardown.
  • Handle BaseExceptionGroup alongside TEST_OUTCOME exceptions.
  • Add a regression test to verify that remaining fixture finalizers execute correctly.

Testing

  • Targeted regression test: PASSED.
  • Test runner module: 70 passed, 1 xfailed.

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 22, 2026

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixes the group case from the issue for me, but a bare CancelledError still leaks the fixture.

Comment thread src/_pytest/runner.py
try:
fin()
except TEST_OUTCOME as e:
except (*TEST_OUTCOME, BaseExceptionGroup) as e:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

With the issue's conftest changed to raise asyncio.CancelledError() (no group), owner is still never released and test_next gets the cached token 1. Doing except (Exit, KeyboardInterrupt): raise then except BaseException as e: here, close to what from_call already lets through, fixes both cases, and test_runner, python/fixtures, unittest and skipping give the same results as this branch.

This branch has not been deployed

No deployments
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.

2 participants