pytest-repeat
A pytest plugin for repeating tests a set number of times
Repository Health
Technical Analysis
pytest-repeat is a small pytest plugin that makes it easy to run a single test, a subset of tests, or an entire suite multiple times in a row. It adds a --count command-line option for repeating everything in a run, plus a @pytest.mark.repeat(n) marker for repeating just specific tests, with a configurable --repeat-scope controlling whether repeats happen per function, class, module, or session.
It’s most commonly reached for when chasing flaky or intermittently failing tests, since repeating a test many times in a row surfaces timing- or state-dependent failures that a single run wouldn’t catch, without needing to write a manual loop inside the test itself.
What You Get
- A
--countCLI flag to repeat every collected test a given number of times in one pytest run - A
@pytest.mark.repeat(n)marker to repeat only specific tests instead of the whole suite - A
--repeat-scopeoption controlling whether repeats are grouped by function, class, module, or session - Automatic parametrization via
pytest_generate_tests, so repeated runs show up as numbered parametrized test IDs - A documented incompatibility warning for
unittest.TestCase-based tests rather than a silent failure
Common Use Cases
- Hunting down flaky or intermittently failing tests by running them dozens or hundreds of times in a row
- Stress-testing code paths with timing, concurrency, or random-input sensitivity across many repeated executions
- Verifying a bug fix for a flaky test actually holds by re-running the previously-failing test many times before merging
- CI pipelines that run a subset of tests repeatedly as a stability gate before a release
Under The Hood
Architecture - The entire plugin lives in a single module, pytest_repeat.py (73 lines), implementing three pytest hooks: pytest_addoption registers the —count and —repeat-scope CLI options, pytest_configure registers the repeat marker so pytest recognizes it without a warning, and pytest_generate_tests reads either the marker’s count or the global —count option and parametrizes the test accordingly via metafunc.parametrize, using a hidden __pytest_repeat_step_number fixture to give each repetition a distinct, visible test ID. Tech Stack - Pure Python with pytest itself as the only runtime dependency (Python 3.9+ and pytest 5+ per the README), packaged with a standard pyproject.toml and no compiled components. Code Quality - test_repeat.py (271 lines, 33 test functions) exercises the marker, the —count flag, all four repeat-scope values, and the unittest.TestCase warning path using pytest’s own testdir/pytester plugin-testing fixtures; CI badges in the README indicate the suite runs on every push, and the codebase carries an MPL 2.0 license header on its source file. API Design - Usage requires no code changes beyond adding —count to a pytest invocation or a repeat(n) marker above a test function, making it one of the lowest-friction ways to add repeated execution to an existing pytest suite.
Used by 2 apps in this directory
ClickHouse
Databases · Analytics · Data Engineering
Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.
Dragonfly
Databases · Developer Tools · Devops
A modern Redis and Memcached replacement engineered for multi-core servers — delivering 25x more throughput, better cache hit rates, and up to 80% lower memory consumption with full API compatibility.