Skip to content

Add --rerun-show-tracebacks to surface retried failures#329

Merged
icemac merged 1 commit into
pytest-dev:masterfrom
vokracko:feat/rerun-show-tracebacks
May 21, 2026
Merged

Add --rerun-show-tracebacks to surface retried failures#329
icemac merged 1 commit into
pytest-dev:masterfrom
vokracko:feat/rerun-show-tracebacks

Conversation

@vokracko
Copy link
Copy Markdown
Contributor

Currently pytest-rerunfailures only emits the traceback for the final attempt of a flaky test. If the last attempt passes, the failures that triggered the reruns are silently discarded; if the last attempt fails, the earlier tracebacks are gone even when they hit a different exception. That makes triaging flaky tests harder than it needs to be — you can see that a test was retried, but not what actually went wrong on each attempt.

This adds --rerun-show-tracebacks, which appends each retried attempt's traceback to the rerun test summary info section. The section is emitted automatically when the flag is set, so -rR is no longer required.

For example, a test that hits a transient assertion twice and passes on the third attempt:

test_demo.py::test_eventually_passes RERUN                               [100%]
test_demo.py::test_eventually_passes RERUN                               [100%]
test_demo.py::test_eventually_passes PASSED                              [100%]
=========================== rerun test summary info ============================
RERUN test_demo.py::test_eventually_passes
>       assert attempt > 2, f"transient failure on attempt {attempt}"
E       AssertionError: transient failure on attempt 1
E       assert 1 > 2
RERUN test_demo.py::test_eventually_passes
>       assert attempt > 2, f"transient failure on attempt {attempt}"
E       AssertionError: transient failure on attempt 2
E       assert 2 > 2

As a side effect, the per-char loop in pytest_terminal_summary is gone. The loop called show_rerun once per matching char in reportchars, so passing -r rR doubled every RERUN line in the summary; the new code calls show_rerun once. Happy to revert that part if the duplication is intentional.

Fixes #156.

Only the final attempt of a flaky test currently produces a traceback,
so failures from earlier attempts -- including those of tests that
eventually pass -- are silently discarded. That makes triaging
intermittent failures much harder than it needs to be: you can see that
something flaked, but not what flaked, unless you happen to be lucky on
the last attempt.

This adds a --rerun-show-tracebacks flag that appends each retried
attempt's traceback to the "rerun test summary info" section. The
section is emitted automatically when the flag is set, so -rR is not
required alongside it.

Fixes pytest-dev#156.
Copy link
Copy Markdown
Contributor

@icemac icemac left a comment

Choose a reason for hiding this comment

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

LGTM.

@icemac icemac merged commit 4a00fac into pytest-dev:master May 21, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please add option to show failure messages for all reruns

3 participants