Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests reported as failures when rerun happened due to exception raised from fixture teardown when using only_rerun #262

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Bug fixes
(`#234 <https://github.com/pytest-dev/pytest-rerunfailures/issues/234>`_)
and (`#241 <https://github.com/pytest-dev/pytest-rerunfailures/issues/241>`_)

- 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>`_)

Breaking changes
++++++++++++++++

Expand All @@ -23,7 +26,6 @@ Features

- Add support for pytest 8.0.


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

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

for report in reports: # 3 reports: setup, call, teardown
# Check all reports to see if any rerun is needed
# (So teardown report is checked before processing call (test))
except_found = False
for report in reports:
rerun_except_errors = _get_rerun_filter_regex(item, "rerun_except")
except_found = rerun_except_errors and _matches_any_rerun_except_error(
rerun_except_errors, report
)
if except_found:
# One of the reports has rerun_except error match,
# no need to scan the other reports
break

should_not_rerun = True
for report in reports:
report.rerun = item.execution_count - 1
if _should_not_rerun(item, report, reruns):
should_not_rerun = _should_not_rerun(item, report, reruns) or except_found
if not should_not_rerun:
# One of the reports should rerun, no need to scan the other reports
break

for report in reports: # 3 reports: setup, call, teardown
if should_not_rerun:
# last run or no failure detected, log normally
item.ihook.pytest_runtest_logreport(report=report)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def pytest_runtest_teardown(item):
assert item.execution_count == 3"""
)
result = testdir.runpytest("--reruns", "2")
assert_outcomes(result, passed=3, rerun=2)
assert_outcomes(result, passed=1, rerun=2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name says that execution_count is exposed to the test runner. So it should be 3 passed tests, as this is set during tear down.

I do not know why this behaviour is here and why it breaks now.



def test_rerun_report(testdir):
Expand Down
Loading