Skip to content

Preserve session and module teardown when fixture teardown fails#319

Merged
icemac merged 2 commits intopytest-dev:masterfrom
emmanuel-ferdman:master
Mar 3, 2026
Merged

Preserve session and module teardown when fixture teardown fails#319
icemac merged 2 commits intopytest-dev:masterfrom
emmanuel-ferdman:master

Conversation

@emmanuel-ferdman
Copy link
Contributor

PR Summary

When a fixture's teardown raised an exception and reruns were enabled, session and module scoped fixture teardowns were never executed. The cleanup logic was clearing the entire setup state stack instead of just removing the failed test item, which inadvertently removed the finalizers for higher-scoped fixtures. This PR fixes that by only removing the current test item from the stack.

Fixes #314.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@icemac
Copy link
Contributor

icemac commented Feb 6, 2026

Hi @emmanuel-ferdman! Thank you for the PR. I really like it. Could you please a an entry in the change log, that would make it perfect.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@emmanuel-ferdman
Copy link
Contributor Author

@icemac Added. thanks for the review!

@icemac
Copy link
Contributor

icemac commented Mar 3, 2026

@emmanuel-ferdman Sorry for letting you waiting so long. Everything is fine, I am going to merge it now.

@icemac icemac enabled auto-merge (squash) March 3, 2026 07:18
@icemac icemac merged commit d9ef70e into pytest-dev:master Mar 3, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

teardown incomplete if fixture raises an exception

2 participants