Skip to content

Commit 4407154

Browse files
committed
Fix tests reported as failures when rerun happened due to exception raised from fixture teardown when using only_rerun
1 parent 3b9ad82 commit 4407154

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CHANGES.rst

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Breaking changes
99

1010
- Drop support for Python 3.7.
1111

12+
Bug fixes
13+
+++++++++
14+
15+
- Fix tests reported as failures when rerun happened due to exception raised from fixture teardown when using only_rerun.
16+
(`#261 <https://github.com/pytest-dev/pytest-rerunfailures/issues/261>`_)
17+
1218
13.0 (2023-11-22)
1319
-----------------
1420

src/pytest_rerunfailures.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,17 @@ def pytest_runtest_protocol(item, nextitem):
534534
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
535535
reports = runtestprotocol(item, nextitem=nextitem, log=False)
536536

537+
# Check all reports to see if any rerun is needed (So teardown report is checked before processing call (test))
538+
should_rerun = False
539+
for r in reports:
540+
r.rerun = item.execution_count - 1
541+
should_rerun = not _should_not_rerun(item, r, reruns)
542+
if should_rerun:
543+
break
544+
545+
537546
for report in reports: # 3 reports: setup, call, teardown
538-
report.rerun = item.execution_count - 1
539-
if _should_not_rerun(item, report, reruns):
547+
if not should_rerun:
540548
# last run or no failure detected, log normally
541549
item.ihook.pytest_runtest_logreport(report=report)
542550
else:

0 commit comments

Comments
 (0)