Repository navigation
Add --reruns-delay-backoff-factor for exponential rerun backoff - #336
Conversation
--reruns-delay-backoff-factor for exponential rerun backoff
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.
|
@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
|
@icemac done. One new issue copilot found after adressing fixes, but i marked it as unnecessary. |
|
Thank you for your PR, I released it in https://pypi.org/project/pytest-rerunfailures/16.4/. |
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.