Add --reruns-delay-backoff-factor for exponential rerun backoff#336
Open
ovsds wants to merge 2 commits into
Open
Add --reruns-delay-backoff-factor for exponential rerun backoff#336ovsds wants to merge 2 commits into
--reruns-delay-backoff-factor for exponential rerun backoff#336ovsds wants to merge 2 commits into
Conversation
--reruns-delay-backoff-factor for exponential rerun backoff
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an exponential backoff capability to pytest-rerunfailures by introducing a new rerun-delay backoff factor that scales the existing --reruns-delay between attempts, with corresponding marker/ini support and documentation/tests.
Changes:
- Add
--reruns-delay-backoff-factorCLI option plus matchingreruns_delay_backoff_factorini setting and marker kwarg. - Apply exponential delay scaling in the rerun loop (
time.sleep) based on attempt count. - Add tests and update docs/changelog to cover the new behavior and negative-factor warning.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/pytest_rerunfailures.py |
Adds the new option/ini + getter and applies backoff factor in the rerun sleep calculation. |
tests/test_pytest_rerunfailures.py |
Adds coverage for CLI, marker, and negative-factor warning behavior. |
README.rst |
Documents the new option and provides usage examples for exponential backoff. |
CHANGES.rst |
Adds changelog entry describing the new feature and its default behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@ovsds Could you please look into the Copilot comments and resolve them? |
Add a reruns-delay-backoff-factor option (with matching reruns_delay_backoff_factor marker kwarg / ini setting) that multiplies the rerun delay after each attempt, so the delay before the n-th re-run is reruns_delay * factor ** (n - 1). Default factor is 1.0, keeping the current constant-delay behaviour unchanged. Includes tests (CLI, marker, negative-factor warning), README docs and a changelog entry.
- Support positional third flaky() arg for the backoff factor and default to 1.0 when a marker is present without the factor (mirrors get_reruns_delay) - Add positional-arg marker test - Use underscore identifiers in README backoff formula
a716562 to
d769995
Compare
Comment on lines
+246
to
+251
| if factor < 0: | ||
| factor = 1.0 | ||
| warnings.warn( | ||
| "Rerun delay backoff factor cannot be < 0. Using default value: 1.0" | ||
| ) | ||
|
|
Author
There was a problem hiding this comment.
same behaviour as in delay, not introducing new layer of complexity
Author
|
@icemac done. One new issue copilot found after adressing fixes, but i marked it as unnecessary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
--reruns-delay-backoff-factoroption (with a matchingreruns_delay_backoff_factormarker kwarg / ini setting) for exponential backoff between reruns. Today--reruns-delayis a fixed delay; this lets the delay grow after each attempt.The delay before the n-th re-run becomes:
The default factor is
1.0, so existing behaviour (a constant delay) is unchanged. A single factor covers both cases —1.0= constant,>1= exponential — so no separate boolean flag is needed.Usage
pytest --reruns 3 --reruns-delay 1 --reruns-delay-backoff-factor 2 # waits 1, 2, 4sImplementation notes
addinimirror the existing--reruns-delaymachinery.get_reruns_delay_backoff_factor()getter mirrorsget_reruns_delay()(marker kwarg → CLI → ini → default1.0), with a< 0guard that warns and falls back to1.0.time.sleep(delay)site in the rerun loop now usesdelay * factor ** (item.execution_count - 1)—execution_countis already the per-attempt counter.Tests / docs
tests/: CLI sequence, marker sequence, and negative-factor warning (full suite: 131 passed, 1 skipped;ruff check/ruff formatclean).README.rst+CHANGES.rstupdated.