pytest-repeat is a plugin for pytest that makes it easy to repeat a single test, or multiple tests, a specific number of times.
Requirements
You will need the following prerequisites in order to use pytest-repeat:
Python 3.9+ or PyPy3
pytest 5 or newer
Installation
To install pytest-repeat:
$ pip install pytest-repeat
Repeating a test
Use the --count command line option to specify how many times you want
your test, or tests, to be run:
$ pytest --count=10 test_file.py
Each test collected by pytest will be run count times.
If you want to mark a test in your code to be repeated a number of times, you
can use the @pytest.mark.repeat(count) decorator:
import pytest
@pytest.mark.repeat(3)
def test_repeat_decorator():
pass
If you want to override default tests executions order, you can use --repeat-scope
command line option with one of the next values: session, module, class or function (default).
It behaves like a scope of the pytest fixture.
function (default) scope repeats each test count or repeat times before executing next test.
session scope repeats whole tests session, i.e. all collected tests executed once, then all such tests executed again and etc.
class and module behaves similar session , but repeating set of tests is a tests from class or module, not all collected tests.
Repeating a test until failure
If you are trying to diagnose an intermittent failure, it can be useful to run the same
test over and over again until it fails. You can use pytest’s -x option in
conjunction with pytest-repeat to force the test runner to stop at the first failure.
For example:
$ pytest --count=1000 -x test_file.py
This will attempt to run test_file.py 1000 times, but will stop as soon as a failure occurs.
UnitTest Style Tests
Unfortunately pytest-repeat is not able to work with unittest.TestCase test classes.
These tests will simply always run once, regardless of --count, and show a warning.
Resources
Release files for pytest-repeat 0.9.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_repeat-0.9.4.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_repeat-0.9.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.7 kB
Release files / pytest_repeat-0.9.4.tar.gz
| Download URL | pytest_repeat-0.9.4.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d92ac14dfaa6ffcfe6917e5d16f0c9bc82380c135b03c2a5f412d2637f224485
|
|
BLAKE2b-256 checksum How to use checksums |
80d469e9dbb9b8266df0b157c72be32083403c412990af15c7c15f7a3fd1b142
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 7, 2025.
Transparency logRelease files / pytest_repeat-0.9.4-py3-none-any.whl
| Download URL | pytest_repeat-0.9.4-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1738b4e412a6f3b3b9e0b8b29fcd7a423e50f87381ad9307ef6f5a8601139f3
|
|
BLAKE2b-256 checksum How to use checksums |
73d48b706b81b07b43081bd68a2c0359fe895b74bf664b20aca8005d2bb3be71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 7, 2025.
Transparency log