Skip to content

Commit 5a1a3b2

Browse files
Initial draft docs (#283)
1 parent 4bbc0be commit 5a1a3b2

File tree

11 files changed

+334
-0
lines changed

11 files changed

+334
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
bin/
1111
build/
1212
dist/
13+
docs/_build/
1314
include/
1415
lib/
1516
pip-selfcheck.json

README.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
pytest-rerunfailures
22
====================
33

4+
.. START-SHORT-DESCRIPTION
5+
46
pytest-rerunfailures is a plugin for `pytest <https://pytest.org>`_ that
57
re-runs tests to eliminate intermittent failures.
68

9+
.. END-SHORT-DESCRIPTION
10+
711
.. image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg
812
:target: https://github.com/pytest-dev/pytest-rerunfailures/blob/master/LICENSE
913
:alt: License
@@ -14,6 +18,8 @@ re-runs tests to eliminate intermittent failures.
1418
:target: https://github.com/pytest-dev/pytest-rerunfailures/actions
1519
:alt: GitHub Actions
1620

21+
.. START-INSTALLATION
22+
1723
Requirements
1824
------------
1925

@@ -40,6 +46,8 @@ To install pytest-rerunfailures:
4046
4147
$ pip install pytest-rerunfailures
4248
49+
.. END-INSTALLATION
50+
4351
Recover from hard crashes
4452
-------------------------
4553

@@ -212,6 +220,8 @@ Here's an example of the output provided by the plugin when run with
212220
Note that output will show all re-runs. Tests that fail on all the re-runs will
213221
be marked as failed.
214222

223+
.. START-COMPATIBILITY
224+
215225
Compatibility
216226
-------------
217227

@@ -222,6 +232,10 @@ Compatibility
222232
`flaky <https://pypi.org/project/flaky/>`_, you can only have
223233
``pytest-rerunfailures`` or ``flaky`` but not both.
224234

235+
.. END-COMPATIBILITY
236+
237+
.. START-CONTRIBUTING
238+
225239
Resources
226240
---------
227241

@@ -239,3 +253,5 @@ Development
239253
@hookimpl(tryfirst=True)
240254
def pytest_runtest_makereport(item, call):
241255
print(item.execution_count)
256+
257+
.. END-CONTRIBUTING

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../CHANGES.rst

docs/cli.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Command Line Interface Options
2+
==============================
3+
4+
.. option:: --only-rerun
5+
6+
**Description**:
7+
Specify regex patterns for errors to rerun. Use this option multiple times to accumulate a list of regexes.
8+
9+
**Type**:
10+
String (repeatable)
11+
12+
**Default**:
13+
None
14+
15+
**Example**:
16+
.. code-block:: bash
17+
18+
pytest --only-rerun AssertionError --only-rerun ValueError
19+
20+
.. option:: --reruns
21+
22+
**Description**:
23+
The number of times to rerun failing tests.
24+
25+
**Type**:
26+
Integer
27+
28+
**Default**:
29+
Not set (must be provided)
30+
31+
**Example**:
32+
.. code-block:: bash
33+
34+
pytest --reruns 5
35+
36+
.. option:: --reruns-delay
37+
38+
**Description**:
39+
Delay in seconds between reruns.
40+
41+
**Type**:
42+
Float
43+
44+
**Default**:
45+
Not set (must be provided)
46+
47+
**Example**:
48+
.. code-block:: bash
49+
50+
pytest --reruns 5 --reruns-delay 1
51+
52+
.. option:: --rerun-except
53+
54+
**Description**:
55+
Specify regex patterns for errors to exclude from reruns. Use this option multiple times to accumulate a list of regexes.
56+
57+
**Type**:
58+
String (repeatable)
59+
60+
**Default**:
61+
None
62+
63+
**Example**:
64+
.. code-block:: bash
65+
66+
pytest --reruns 5 --rerun-except AssertionError --rerun-except OSError
67+
68+
.. option:: --fail-on-flaky
69+
70+
**Description**:
71+
If set, the test run will fail with exit code 7 if a flaky test passes on rerun.
72+
73+
**Type**:
74+
Boolean flag
75+
76+
**Default**:
77+
False
78+
79+
**Example**:
80+
.. code-block:: bash
81+
82+
pytest --fail-on-flaky

docs/conf.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
import sys
3+
from datetime import datetime, timezone
4+
5+
sys.path.insert(0, os.path.abspath("../src"))
6+
7+
project = "pytest-rerunfailures"
8+
copyright = (
9+
f"2012-{datetime.now(tz=timezone.utc).year}, Leah Klearman and pytest-dev team"
10+
)
11+
author = "Leah Klearman"
12+
13+
extensions = [
14+
"sphinx.ext.autodoc",
15+
]
16+
17+
templates_path = ["_templates"]
18+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
19+
20+
html_theme = "sphinx_rtd_theme"
21+
html_static_path = ["_static"]

docs/configuration.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Configuration
2+
=============
3+
4+
The ``pytest.ini`` configuration file allows you to set default values for the plugin's options,
5+
enabling a consistent test execution environment without the need to specify :doc:`command-line options </cli>` every time.
6+
7+
Available ``pytest.ini`` Options
8+
--------------------------------
9+
10+
Below are the ``pytest.ini`` options supported by the plugin:
11+
12+
``reruns``
13+
^^^^^^^^^^
14+
15+
- **Description**: Sets the default number of times to rerun failed tests. If not set, you must provide the :option:`--reruns` option on the command line.
16+
- **Type**: String
17+
- **Default**: Not set (must be provided as a CLI argument if not configured).
18+
- **Example**:
19+
20+
.. code-block:: ini
21+
22+
[pytest]
23+
reruns = 3
24+
25+
``reruns_delay``
26+
^^^^^^^^^^^^^^^^
27+
28+
- **Description**: Sets the default delay (in seconds) between reruns of failed tests.
29+
- **Type**: String
30+
- **Default**: Not set (optional).
31+
- **Example**:
32+
33+
.. code-block:: ini
34+
35+
[pytest]
36+
reruns_delay = 2.5
37+
38+
Example
39+
-------
40+
41+
To configure your test environment for consistent retries and delays, add the following options to your ``pytest.ini`` file:
42+
43+
.. code-block:: ini
44+
45+
[pytest]
46+
reruns = 3
47+
reruns_delay = 2.0
48+
49+
This setup ensures that:
50+
51+
- Failed tests will be retried up to 3 times.
52+
- There will be a 2-second delay between each retry.
53+
54+
Overriding ``pytest.ini`` Options
55+
---------------------------------
56+
57+
Command-line arguments always override ``pytest.ini`` settings. For example:
58+
59+
.. code-block:: bash
60+
61+
pytest --reruns 5 --reruns-delay 1.5
62+
63+
This will retry tests 5 times with a 1.5-second delay, regardless of the values set in ``pytest.ini``.

docs/contributing.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. include:: ../CONTRIBUTING.rst
2+
3+
.. include:: ../README.rst
4+
:start-after: .. START-CONTRIBUTING
5+
:end-before: .. END-CONTRIBUTING

docs/index.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pytest-rerunfailures
2+
====================
3+
4+
.. include:: ../README.rst
5+
:start-after: .. START-SHORT-DESCRIPTION
6+
:end-before: .. END-SHORT-DESCRIPTION
7+
8+
.. toctree::
9+
:maxdepth: 2
10+
:caption: Contents:
11+
12+
installation
13+
quickstart
14+
cli
15+
configuration
16+
mark
17+
contributing
18+
changelog

docs/installation.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Requirements and Installation
2+
=============================
3+
4+
.. include:: ../README.rst
5+
:start-after: .. START-INSTALLATION
6+
:end-before: .. END-INSTALLATION
7+
8+
.. include:: ../README.rst
9+
:start-after: .. START-COMPATIBILITY
10+
:end-before: .. END-COMPATIBILITY

docs/mark.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Mark Specific Tests as Flaky
2+
============================
3+
4+
The ``@pytest.mark.flaky`` decorator allows you to mark individual tests as flaky and configure them to
5+
automatically re-run a specified number of times upon failure. This is particularly useful for specific tests
6+
that are intermittently failing due to non-deterministic conditions (e.g., network latency, race conditions).
7+
That mark also allows to override global settings specified via :doc:`command-line options </cli>`.
8+
9+
Basic Usage
10+
-----------
11+
12+
To use the ``@pytest.mark.flaky`` decorator, include it in your test function and specify the number of retries using the ``reruns`` argument:
13+
14+
.. code-block:: python
15+
16+
@pytest.mark.flaky(reruns=3)
17+
def test_example():
18+
import random
19+
assert random.choice([True, False])
20+
21+
In this example, ``test_example`` will automatically re-run up to 3 times if it fails.
22+
23+
Additional Options
24+
------------------
25+
26+
The ``@pytest.mark.flaky`` decorator supports the following optional arguments:
27+
28+
``reruns_delay``
29+
^^^^^^^^^^^^^^^^
30+
31+
Specify a delay (in seconds) between re-runs.
32+
33+
.. code-block:: python
34+
35+
@pytest.mark.flaky(reruns=5, reruns_delay=2)
36+
def test_example():
37+
import random
38+
assert random.choice([True, False])
39+
40+
This will retry the test 5 times with a 2-second pause between attempts.
41+
42+
``condition``
43+
^^^^^^^^^^^^^
44+
45+
Re-run the test only if a specified condition is met.
46+
The condition can be any expression that evaluates to ``True`` or ``False``.
47+
48+
.. code-block:: python
49+
50+
import sys
51+
52+
@pytest.mark.flaky(reruns=3, condition=sys.platform.startswith("win32"))
53+
def test_example():
54+
import random
55+
assert random.choice([True, False])
56+
57+
In this example, the test will only be re-run if the operating system is Windows.
58+
59+
60+
``only_rerun``
61+
^^^^^^^^^^^^^^
62+
63+
Re-run the test only for specific exception types or patterns.
64+
That overrides the :option:`--only-rerun` command-line option.
65+
66+
.. code-block:: python
67+
68+
@pytest.mark.flaky(reruns=5, only_rerun=["AssertionError", "ValueError"])
69+
def test_example():
70+
raise AssertionError()
71+
72+
``rerun_except``
73+
^^^^^^^^^^^^^^^^
74+
75+
Exclude specific exception types or patterns from triggering a re-run.
76+
That overrides the :option:`--rerun-except` command-line option.
77+
78+
.. code-block:: python
79+
80+
@pytest.mark.flaky(reruns=5, rerun_except="AssertionError")
81+
def test_example():
82+
raise ValueError()

0 commit comments

Comments
 (0)