Skip to content

Commit b53ef72

Browse files
icemacCopilot
andauthored
Fix support for pytest-main. (#324)
* Fix support for pytest-main. Fixes #323 * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent d9ef70e commit b53ef72

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ 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+
Fixes `#323 <https://github.com/pytest-dev/pytest-rerunfailures/issues/323>`_.
14+
1015

1116
16.1 (2025-10-10)
1217
-----------------

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)