skillfed

pytest-loop

pytest plugin for looping tests

pytest-loop v1.0.13 321.5K downloads/30d#7,622 on PyPI7
Copyleft 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) Active released

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-loop

uv

uv add pytest-loop

poetry

poetry add pytest-loop

Installing 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

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)Operating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTopic :: Utilities

Tags

pytest repeat tests multiple timespytest loop tests durationpytest stress testing pluginpytest intermittent failure detectionpytest test repetitionpytest time-based test loopingpytest flaky test diagnosis
pytest-pluginflaky-test-diagnosisstress-testing

More Utilities packages