Skip to content
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
1 change: 1 addition & 0 deletions changes/366.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mark teardown failures from an attempt that is rerun as reruns, so a later successful attempt is not reported as an error.
2 changes: 2 additions & 0 deletions src/pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,8 @@ def pytest_runtest_protocol(item, nextitem):
for report in reports: # 3 reports: setup, call, teardown
report.rerun = item.execution_count - 1
if rerun_triggered:
if report.failed:
report.outcome = "rerun"
item.ihook.pytest_runtest_logreport(report=report)
elif (
condition
Expand Down
26 changes: 23 additions & 3 deletions tests/test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,30 @@ def pytest_sessionfinish():

stdout = result.stdout.str()
assert "ATTEMPTS: 2" in stdout
assert (
"FIRST ATTEMPT REPORTS: [('call', 'rerun'), ('teardown', 'failed')]" in stdout
assert "FIRST ATTEMPT REPORTS: [('call', 'rerun'), ('teardown', 'rerun')]" in stdout


def test_call_and_teardown_failures_are_rerun_together(testdir):
testdir.makepyfile(
"""
import pytest

@pytest.fixture
def demo_fixture(request):
yield
if request.node.execution_count == 1:
raise RuntimeError("teardown failure")

def test_demo(demo_fixture, request):
if request.node.execution_count == 1:
pytest.fail("call failure")
"""
)

result = testdir.runpytest("--reruns", "1")

assert_outcomes(result, passed=1, rerun=2, failed=0, error=0)


def test_pytest_runtest_logfinish_is_called(testdir):
hook_message = "Message from pytest_runtest_logfinish hook"
Expand Down Expand Up @@ -1959,7 +1979,7 @@ def test_fail(broken_fixture):
)

result = testdir.runpytest("-s")
assert_outcomes(result, passed=0, failed=1, error=3, rerun=2)
assert_outcomes(result, passed=0, failed=1, error=1, rerun=4)
assert result.stdout.str().count("module teardown") == 1


Expand Down