Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,31 @@ Each retried attempt's traceback is appended to the ``rerun test summary
info`` section. The section is emitted automatically when the flag is set,
so ``-rR`` is not required.

Per-failure rerun policy (hook)
-------------------------------

Plugins can give a *specific failure class* its own rerun count and semantics via the
``pytest_rerunfailures_rerun_policy`` hook, without changing how other failures are
rerun. The hook is called once per test, on its first failing report, and returns a
``RerunPolicy`` (or ``None`` for the default behavior):

.. code-block:: python

# conftest.py
from pytest_rerunfailures import RerunPolicy

def pytest_rerunfailures_rerun_policy(item, report, call):
# e.g. give transient provider/infra errors one rerun, pass on recovery —
# while other failures keep the global --reruns / --all-reruns-need-to-pass
# behavior.
exc = call.excinfo.value if call.excinfo else None
if isinstance(exc, ConnectionError):
return RerunPolicy(reruns=1, all_reruns_need_to_pass=False)
return None

``RerunPolicy`` fields left ``None`` keep the plugin's default for that item. The policy
is fixed at the item's first failure and applies to its whole rerun sequence.

Output
------

Expand Down
8 changes: 8 additions & 0 deletions changes/311.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Add the ``--all-reruns-need-to-pass`` option (also available as an ini setting
and as the ``all_reruns_need_to_pass`` argument of the ``flaky`` marker): after
an initial failure, every rerun must pass for the test to succeed. Higher-scoped
fixtures stay alive across the attempts of such a sequence.

Add the ``pytest_rerunfailures_rerun_policy`` hook: plugins can return a
``RerunPolicy`` to give a specific failure class its own rerun count /
all-reruns-need-to-pass mode, without changing how other failures are rerun.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ release = [
"zestreleaser-towncrier>=2",
]

[tool.setuptools]
package-dir = { "" = "src" }
py-modules = [ "pytest_rerunfailures", "pytest_rerunfailures_newhooks" ]

[tool.setuptools.dynamic]
readme = { file = [ "HEADER.rst", "README.rst", "CHANGES.rst" ] }

Expand Down
Loading