Skip to content

Report fixture teardown errors before interrupted sessions finish - #15357

Open
iamabhisheknag wants to merge 1 commit into
pytest-dev:mainfrom
iamabhisheknag:codex/report-teardown-on-interrupt
Open

iamabhisheknag wants to merge 1 commit into
pytest-dev:mainfrom
iamabhisheknag:codex/report-teardown-on-interrupt

Conversation

@iamabhisheknag

@iamabhisheknag iamabhisheknag commented Nov 9, 2026 •

Copy link
Copy Markdown

Fixes #8750.

When pytest.exit() or a keyboard interrupt occurs during setup or a test call, fixture teardown currently happens during session shutdown. A teardown failure can then escape as an unhandled exception after the JUnit XML has been written, masking the requested exit code and omitting the error from the report.

Run the normal teardown reporting path before reraising the interruption, releasing fixtures of every scope. Preserve the requested exit status and include teardown errors in the reports. Also distinguish JUnit reporters created only for setup timing from reporters with an actual outcome, so an interrupted call followed by a teardown error is counted once.

Validation: all 12 new subprocess regression cases fail on unpatched main and pass with the fix. They cover setup/call interruptions, function/session fixture scopes, pytest.exit, explicit status 99, and KeyboardInterrupt. Relevant runner, main, terminal, JUnit, fixture, capture, and logging tests: 963 passed, 3 skipped, 5 xfailed. Mypy passes on the three changed Python files; pinned Ruff checks and formatting pass. The full suite and full pre-commit suite have not been run.

  • Add regression tests.
  • Reference the issue, add a changelog entry, and update AUTHORS.
  • Allow edits by maintainers.

AI disclosure: the reproduction, patch, tests, and this description were prepared with AI assistance. The account holder confirmed review and understanding of the change and authorized upstream submission. No production incident is claimed.

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 9, 2026
Run teardown reporting before reraising setup/call interruptions.
Preserve requested exit codes and correct interrupted JUnit testcase counts.
Include regression coverage, changelog, and author credit.

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.

Incorrect mixture of exit code and jUnit report when pytest.exit is called and a fixture teardown fails

1 participant