pytest-loop
pytest plugin for looping tests
What it is and what it does
pytest-loop is a pytest plugin that lets you run the same test or test suite repeatedly—either a fixed number of times or for a specified duration (hours, minutes, seconds). It's designed to help diagnose intermittent test failures by running tests many times in succession, and to perform stress testing by running tests continuously over a time window.
The plugin integrates with pytest's command-line interface and decorator system. You can specify repetition via `--loop=N` on the command line, or mark individual tests with `@pytest.mark.loop(N)`. For time-based looping, you use `--hours`, `--minutes`, and `--seconds` options, optionally with a `--delay` between iterations. It merges functionality from pytest-repeat and pytest-stress, and works with standard pytest test functions but not with unittest.TestCase classes.
Use it for:
- Run a flaky test 1000 times with `-x` to stop at first failure and capture the failure condition.
- Stress-test a test suite for 8 hours to detect resource leaks or timing-dependent bugs.
- Mark a specific test with `@pytest.mark.loop(5)` to repeat only that test without modifying the command line.
- Diagnose race conditions by looping concurrent or async tests for an extended duration.
- Verify test stability before merging by running the full suite repeatedly for a fixed time window.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that repeats tests a fixed number of times or for a specified duration, useful for detecting intermittent failures and stress-testing.
Yes. The plugin is actively maintained, has no known vulnerabilities, and solves a real problem—detecting intermittent failures and stress-testing. Low install friction (one dependency, pure Python), broad Python version support, and Production/Stable status make it a safe choice for projects that need to diagnose flaky tests or validate stability under repeated execution.
Install
pytest-loop on PyPI
pip
pip install pytest-loopuv
uv add pytest-looppoetry
poetry add pytest-loopInstalling pytest-loop
Before you install
Low friction: pure Python wheel with only pytest as a runtime dependency. Actively maintained with recent commits and marked Production/Stable.
License in practice
Licensed under Mozilla Public License 2.0 (copyleft). You must disclose source modifications and distribute under the same license if you modify and redistribute the package; using it unmodified as a dependency carries minimal obligation.
Quickstart
pip install pytest-loop
pytest --loop=10 test_file.py
# Or with decorator:
import pytest
@pytest.mark.loop(3)
def test_example():
pass
Requires Python 3.7+ and pytest 7 or newer. Does not work with unittest.TestCase test classes.
Verify before relying
- Whether the package handles test collection and result aggregation correctly across all pytest versions in the 7+ range.
- Performance impact of looping on large test suites or when combined with other pytest plugins.
Package facts
| License | This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at… (full text in the JSON record) (copyleft) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | actively maintained — 666 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 321,529/month — #7,622 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_loop-1.0.13-py3-none-any.whl
Keywords: duration, loop, pytest, pytest-loop, pytest-repeat, pytest-rerun, pytest-stress, repeat, rerun, stress, test, time
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytest-repeatA pytest plugin that repeats test execution a…
copyleft · top 5,000 on PyPI
pytest-retrypytest-retry is a pytest plugin that…
permissive · top 5,000 on PyPI
pytest-flakefinderA pytest plugin that runs tests multiple times…
permissive · top 5,000 on PyPI
looptimeLooptime fakes the passage of time in asyncio…
permissive · top 15,000 on PyPI
python-timeoutGenerates random timeouts between specified…
unclear · top 15,000 on PyPI
pytest-dependsA pytest plugin that lets you declare…
permissive · top 15,000 on PyPI
pytest-checkA pytest plugin that allows tests to continue…
unclear · top 5,000 on PyPI
pytest-rerunfailuresA pytest plugin that automatically reruns…
copyleft · top 1,000 on PyPI
pytest-fail-slowA pytest plugin that marks tests as failed if…
permissive · top 15,000 on PyPI
flakyA pytest plugin that automatically reruns…
permissive · top 5,000 on PyPI