Skip to content

Commit

Permalink
Fix tests reported as failures when rerun happened due to exception r…
Browse files Browse the repository at this point in the history
…aised from fixture teardown when using only_rerun
  • Loading branch information
samitAtsyna committed Feb 25, 2024
1 parent 3b9ad82 commit 20e1315
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Breaking changes

- Drop support for Python 3.7.

Bug fixes
+++++++++

- Fix tests reported as failures when rerun happened due to exception raised from fixture teardown when using only_rerun.
(`#261 <https://github.com/pytest-dev/pytest-rerunfailures/issues/261>`_)

13.0 (2023-11-22)
-----------------

Expand Down
12 changes: 10 additions & 2 deletions src/pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,17 @@ def pytest_runtest_protocol(item, nextitem):
item.ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
reports = runtestprotocol(item, nextitem=nextitem, log=False)

# Check all reports to see if any rerun is needed (So teardown report is checked before processing call (test))
should_rerun = False
for r in reports:
r.rerun = item.execution_count - 1
should_rerun = not _should_not_rerun(item, r, reruns)
if should_rerun:
break


for report in reports: # 3 reports: setup, call, teardown
report.rerun = item.execution_count - 1
if _should_not_rerun(item, report, reruns):
if not should_rerun:
# last run or no failure detected, log normally
item.ihook.pytest_runtest_logreport(report=report)
else:
Expand Down

0 comments on commit 20e1315

Please sign in to comment.