pytest-repeat

A pytest plugin for repeating tests a set number of times

Tool
PyPI
v0.9.4
194stars
Mozilla Public License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
43/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
67/100Good
Architecture65
Code Quality72
Innovation45
Learning Curve85

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 --count CLI 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-scope option 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search