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
3 changes: 3 additions & 0 deletions changes/45.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Include reruns in the summary when ``-ra``/``-rA`` ("all") is passed, so
``pytest -ra`` now shows the ``rerun test summary info`` section without
requiring ``-rR``.
6 changes: 5 additions & 1 deletion src/pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,11 @@ def pytest_terminal_summary(terminalreporter):
# Adapted from https://pytest.org/latest/_modules/_pytest/skipping.html
tr = terminalreporter
show_tracebacks = tr.config.getoption("rerun_show_tracebacks", False)
if not show_tracebacks and not any(c in "rR" for c in tr.reportchars):
# -rR selects reruns explicitly; -ra/-rA ("all") should include them too,
# but pytest expands those flags before tr.reportchars is set, so check the
# raw option instead.
requested = tr.config.option.reportchars
if not show_tracebacks and not any(c in "rRaA" for c in requested):
Comment on lines +1378 to +1382

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reading the raw -r option bypasses pytest's N reset, so the rerun summary now escapes a reset that used to suppress it.

getreportopt() treats N as "reset the list": for -raN it first expands a and then clears everything, leaving reportopts == "". Since this check only scans the raw string for any of rRaA, the a still matches and the section is printed.

Confirmed against pytest 9.1.1 with a flaky test and --reruns 1:

flags master this PR
-raN no section section printed
-ra no section section printed (intended)

Honouring only the part after the last N matches pytest's own semantics, and keeping tr.reportchars in the check preserves the explicit R path (plus anything that appends to reportchars at runtime). Full suite (252 tests) passes with this, -raN goes back to printing nothing, and -rNa still prints — consistent with pytest, which reports after a reset too.

Suggested change
# -rR selects reruns explicitly; -ra/-rA ("all") should include them too,
# but pytest expands those flags before tr.reportchars is set, so check the
# raw option instead.
requested = tr.config.option.reportchars
if not show_tracebacks and not any(c in "rRaA" for c in requested):
# -rR selects reruns explicitly; -ra/-rA ("all") should include them too,
# but pytest expands those flags before tr.reportchars is set, so check the
# raw option as well. "N" resets the list, so only honour what follows the
# last reset.
requested = tr.reportchars + tr.config.option.reportchars.rsplit("N", 1)[-1]
if not show_tracebacks and not any(c in "rRaA" for c in requested):

— Comment created by Claude

return

lines = show_rerun(terminalreporter, show_tracebacks=show_tracebacks)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_pytest_rerunfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,19 @@ def test_skips(bad_teardown):
]


@pytest.mark.parametrize("report_flag", ["-ra", "-rA"])
def test_extra_test_summary_for_reruns_with_reportchars_all(testdir, report_flag):
testdir.makepyfile(
f"""
def test_pass():
{temporary_failure()}"""
)
result = testdir.runpytest("--reruns", "1", report_flag)
result.stdout.fnmatch_lines_random(["RERUN test_*:*"])
assert "rerun test summary info" in result.stdout.str()
assert "1 rerun" in result.stdout.str()


def test_rerun_show_tracebacks_for_eventual_pass(testdir):
testdir.makepyfile(
f"""
Expand Down
Loading