--- id: pytest-loop version: "1.0.13" 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) license_treatment: copyleft maintenance: active --- # pytest-loop — pytest plugin for looping tests License: copyleft · Maintenance: active · Downloads: 321.5K/mo ## 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 above — 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 pip install pytest-loop uv add pytest-loop 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_current - Install friction: low - Maintenance: active - Downloads: 321.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest repeat tests multiple times, pytest loop tests duration, pytest stress testing plugin, pytest intermittent failure detection, pytest test repetition, pytest time-based test looping, pytest flaky test diagnosis, pytest-plugin, flaky-test-diagnosis, stress-testing [View on SkillFed](https://skillfed.io/packages/pytest-loop) · [View on PyPI](https://pypi.org/project/pytest-loop/)