Skip to content

runner: catch BaseExceptionGroup during teardown (fixes #15329) - #15330

Open
ege-arhan wants to merge 1 commit into
pytest-dev:mainfrom
ege-arhan:fix/15329-teardown-base-exception-group
Open

ege-arhan wants to merge 1 commit into
pytest-dev:mainfrom
ege-arhan:fix/15329-teardown-base-exception-group

Conversation

@ege-arhan

Copy link
Copy Markdown

Summary

Fixes #15329.

When a fixture raises a BaseExceptionGroup (such as one containing asyncio.CancelledError or GeneratorExit) during teardown, SetupState.teardown_exact() previously failed to catch it because the loop only caught TEST_OUTCOME = (OutcomeException, Exception). As a result, execution aborted before remaining item finalizers could run, leaving dependent fixtures uncleared in the fixture cache and leaking into subsequent tests.

This PR updates the teardown catch in SetupState.teardown_exact() to (*TEST_OUTCOME, BaseExceptionGroup), allowing finalizer draining to complete while aggregating all teardown exceptions.

Repro & Verification

  1. Local reproducer from BaseExceptionGroup during fixture teardown skips remaining finalizers and reuses a cached function-scoped fixture #15329 (test_lifecycle.py with an owner fixture and resource fixture raising BaseExceptionGroup("cleanup", [asyncio.CancelledError("cancel marker"), RuntimeError("ordinary marker")])):

    • Before: test_first error, test_next failed (AssertionError: cached function-scoped owner reused, token 1 reused instead of new allocation).
    • After: test_first error, test_next passed (token == 2).
  2. Tests run:

    • pytest testing/test_runner.py: 71 passed, 1 xfailed.

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

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.

BaseExceptionGroup during fixture teardown skips remaining finalizers and reuses a cached function-scoped fixture

1 participant