-
Notifications
You must be signed in to change notification settings - Fork 108
Add --rerun-warning flag to emit a warning on each scheduled rerun #375
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add ``--rerun-warning`` flag that emits a ``PytestWarning`` each time a test | ||
| is scheduled for rerun, to surface flaky tests in CI (e.g. via | ||
| pytest-github-actions-annotate-failures annotations). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,6 +178,15 @@ def pytest_addoption(parser): | |
| "'rerun test summary info' section, which is emitted automatically " | ||
| "when this flag is set.", | ||
| ) | ||
| group._addoption( | ||
| "--rerun-warning", | ||
| action="store_true", | ||
| dest="rerun_warning", | ||
| help="Emit a PytestWarning each time a test is scheduled for rerun. " | ||
| "Useful to surface flaky tests in CI, e.g. via annotations from " | ||
| "pytest-github-actions-annotate-failures. Note that " | ||
| "filterwarnings=error turns these warnings into errors.", | ||
| ) | ||
| group.addoption( | ||
| "--max-suite-reruns", | ||
| action="store", | ||
|
|
@@ -1337,6 +1346,13 @@ def pytest_runtest_protocol(item, nextitem): | |
| continue | ||
|
|
||
| report.outcome = "rerun" | ||
| if item.session.config.option.rerun_warning: | ||
| item.warn( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. — Comment created by Claude Bug (high):
The help text and README say only that the warnings "turn into errors". Users will read that as a failing test, not an aborted session. Fix options: emit the warning in a way that cannot abort the protocol (for example, catch the exception and fail the test), or document the real behaviour clearly. A test covering |
||
| pytest.PytestWarning( | ||
| f"{item.nodeid} failed on attempt " | ||
| f"{item.execution_count} and will be rerun" | ||
| ) | ||
| ) | ||
| time.sleep(delay * delay_backoff_factor ** (item.execution_count - 1)) | ||
|
|
||
| if not parallel or works_with_current_xdist(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
— Comment created by Claude
Gap (low): worker-crash reruns under xdist emit no warning.
The warning is only emitted on this in-process rerun path.
XDistHooks.pytest_handlecrashitemalso schedules reruns (sched.mark_test_pending(crashitem)/report.outcome = "rerun") and does not checkrerun_warning. So with-nand--rerun-warning, a test that crashes its worker and is rerun gets no annotation. The help text promises a warning "each time a test is scheduled for rerun". Either emit a warning on that path too, or narrow the wording.