Skip to content

Add --reruns-on-exitfirst to override rerun count under -x/--maxfail - #377

Open
LouisDeconinck wants to merge 2 commits into
pytest-dev:masterfrom
LouisDeconinck:issue-249-reruns-on-exitfirst
Open

LouisDeconinck wants to merge 2 commits into
pytest-dev:masterfrom
LouisDeconinck:issue-249-reruns-on-exitfirst

Conversation

@LouisDeconinck

@LouisDeconinck LouisDeconinck commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds --reruns-on-exitfirst N: when -x/--exitfirst or --maxfail is given, the rerun count for every test becomes N instead of the global/marker setting
  • --reruns-on-exitfirst 0 makes -x exit on the first failure immediately, without waiting for reruns
  • --force-reruns still wins; negative values are rejected with a UsageError

Closes #249

Test plan

  • -x --reruns-on-exitfirst 0 disables global and marker reruns
  • Non-zero value limits reruns under -x
  • Applies under --maxfail too; behavior unchanged without the option; negative value rejected

With -x/--exitfirst (or --maxfail), reruns previously still ran to
completion before the session could exit on the first failure. The new
option sets the rerun count used in that situation, e.g.
--reruns-on-exitfirst 0 to fail fast.

Closes pytest-dev#249.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

--reruns-on-exitfirst can enable reruns under --pdb without tripping the existing incompatibility check. check_options() only considers --force-reruns / the global rerun setting, while get_reruns_count() now returns this new value whenever maxfail is active. Thus pytest -x --pdb --reruns-on-exitfirst 1 is accepted and will rerun failures even though the plugin otherwise rejects reruns with PDB. Please include the new option in the --pdb validation and add that no-global-reruns case to the tests.

The option enables reruns under -x/--maxfail even without a global rerun
count, so it bypassed the existing --pdb incompatibility check.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@LouisDeconinck

Copy link
Copy Markdown
Contributor Author

Fixed in 7da4ffb: check_options() now treats --reruns-on-exitfirst as enabling reruns under -x/--maxfail when no other rerun count is set, so pytest -x --pdb --reruns-on-exitfirst 1 is rejected. Added regression tests for the error and the 0 opt-out case.

@LouisDeconinck

Copy link
Copy Markdown
Contributor Author

Fixed — check_options() now rejects --reruns-on-exitfirst under --pdb alongside the other rerun options, with tests covering both the rejected case and the zero-value opt-out (7da4ffb).

sylvesterkaczmarek

This comment was marked as duplicate.

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.

[RFC] --reruns-on-exitfirst: set reruns with --exitfirst / -x

2 participants