Skip to content

Add rerun_if() to request a rerun from inside a test - #382

Open
LouisDeconinck wants to merge 1 commit into
pytest-dev:masterfrom
LouisDeconinck:issue-58-rerun-if
Open

LouisDeconinck wants to merge 1 commit into
pytest-dev:masterfrom
LouisDeconinck:issue-58-rerun-if

Conversation

@LouisDeconinck

@LouisDeconinck LouisDeconinck commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds rerun_if(condition, reason=None) and the RerunRequest exception: inside a test, rerun_if(...) aborts the current attempt and retries while the test still has reruns (@pytest.mark.flaky(reruns=N) or --reruns)
  • Covers the hypothesis.assume()-style use case from the issue; combining with only_rerun=[RerunRequest] restricts reruns to exactly the requested condition rather than any failure
  • Without a rerun budget the request is a normal test failure

Closes #58

Test plan

  • rerun_if inside a flaky test reruns and passes
  • only_rerun=[RerunRequest] does not rerun other failures
  • No rerun budget → normal failure

Expose a RerunRequest exception and a rerun_if(condition, reason) helper
that discards the current attempt and retries while the test still has
reruns left. Combined with only_rerun=[RerunRequest], tests can restrict
reruns to exactly the known-bad generated-data case instead of any
failure.

Closes pytest-dev#58.

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

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

Feature request: rerun test if condition is not met (similar to hypothesis.assume())

1 participant