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 5 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
19 changes: 17 additions & 2 deletions src/pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,24 @@ 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))
except_found = False
for r 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, r
)
if except_found:
break

should_not_rerun = True
for r in reports:
icemac marked this conversation as resolved.
Show resolved Hide resolved
r.rerun = item.execution_count - 1
should_not_rerun = _should_not_rerun(item, r, reruns) or except_found

for report in reports: # 3 reports: setup, call, teardown
report.rerun = item.execution_count - 1
if _should_not_rerun(item, report, reruns):
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