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/388.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep zero-delay reruns running when a large backoff factor would overflow before multiplication by zero.
7 changes: 6 additions & 1 deletion src/pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,12 @@ def pytest_runtest_protocol(item, nextitem):
continue

report.outcome = "rerun"
time.sleep(delay * delay_backoff_factor ** (item.execution_count - 1))
rerun_delay = (
0
if delay == 0
else delay * delay_backoff_factor ** (item.execution_count - 1)
)
time.sleep(rerun_delay)

if not parallel or works_with_current_xdist():
# will rerun test, log intermediate result
Expand Down
28 changes: 28 additions & 0 deletions tests/test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,34 @@ def test_fail():
assert_outcomes(result, passed=0, failed=1, rerun=3)


def test_reruns_with_zero_delay_and_large_backoff_factor(testdir):
testdir.makepyfile(
"""
from pathlib import Path

def test_recovers_on_fourth_attempt():
count_file = Path(__file__).with_suffix('.count')
count = int(count_file.read_text()) + 1 if count_file.exists() else 1
count_file.write_text(str(count))
assert count == 4
"""
)

time.sleep = mock.MagicMock()

result = testdir.runpytest(
"--reruns",
"3",
"--reruns-delay",
"0",
"--reruns-delay-backoff-factor",
"1e308",
)

assert time.sleep.call_args_list == [mock.call(0)] * 3
assert_outcomes(result, passed=1, rerun=3)


def test_reruns_with_delay_backoff_factor_marker(testdir):
testdir.makepyfile(
"""
Expand Down