Skip to content

Commit c39a940

Browse files
committed
Fix support for pytest-main.
Fixes #323
1 parent d9ef70e commit c39a940

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Changelog
77
- Fix missing teardown for session and module scoped fixtures when fixture teardown fails.
88
Fixes `#314 <https://github.com/pytest-dev/pytest-rerunfailures/issues/314>`_.
99

10+
- Clear fixture finalizers when removing cached results from failed fixtures
11+
to fix compatibility with pytest >= 9, which asserts that ``_finalizers`` is
12+
empty before executing a fixture.
13+
1014

1115
16.1 (2025-10-10)
1216
-----------------

src/pytest_rerunfailures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ def _remove_cached_results_from_failed_fixtures(item):
244244
result, _, err = getattr(fixture_def, cached_result)
245245
if err: # Deleting cached results for only failed fixtures
246246
setattr(fixture_def, cached_result, None)
247+
# Clear finalizers registered during the failed execution
248+
# so the fixture can be re-executed cleanly (pytest >= 9
249+
# asserts _finalizers is empty before executing a fixture).
250+
if hasattr(fixture_def, "_finalizers"):
251+
fixture_def._finalizers.clear()
247252

248253

249254
def _remove_failed_setup_state_from_session(item):

0 commit comments

Comments
 (0)