pytest-run-parallel
A simple pytest plugin to run tests concurrently
What it is and what it does
pytest-run-parallel is a pytest plugin that executes test functions multiple times concurrently in a thread pool, rather than running different tests in parallel. Its primary purpose is stress-testing code for thread-safety issues, especially important for libraries that use C extensions and will run under free-threaded Python (PEP 703). The plugin is not a replacement for pytest-xdist; it focuses on discovering race conditions and GIL-related bugs by running the same test repeatedly across multiple threads with synchronized startup via a barrier.
The plugin provides command-line flags (--parallel-threads, --iterations, --skip-thread-unsafe, --forever) and per-test markers to control thread count and iteration behavior. It includes fixtures for thread and iteration indices, and patches tmp_path and tmpdir to be thread-safe. A key caveat: pytest itself is not thread-safe, so tests must account for shared fixture state across threads and avoid dynamically setting marks.
Use it for:
- Validate that C extension libraries work correctly under free-threaded Python builds before PEP 703 adoption
- Stress-test thread safety of libraries by running the same test repeatedly in parallel threads to catch race conditions
- Detect GIL-related bugs and verify behavior when the GIL is disabled in CPython implementations
- Reproduce intermittent threading bugs by running tests in an endless loop (--forever) until failure occurs
- Verify that pytest fixtures and test setup code handle concurrent access without data corruption
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that runs test functions concurrently in a thread pool to discover thread-safety issues, particularly useful for validating C library compatibility with free-threaded Python implementations.
Yes, if you maintain a library with C extensions or are preparing for free-threaded Python adoption. The plugin is actively maintained, has no security vulnerabilities, and solves a specific and growing need. Install with caution if your test suite relies heavily on mutable shared state via fixtures—you will need to refactor tests to be thread-safe first.
Install
pytest-run-parallel on PyPI
pip
pip install pytest-run-paralleluv
uv add pytest-run-parallelpoetry
poetry add pytest-run-parallelInstalling pytest-run-parallel
Before you install
Low friction: pure Python wheel with only pytest as a runtime dependency. Actively maintained with a recent release (10 days old) and steady development since first release in 2024-09-30.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal obligations—suitable for any project type.
Quickstart
pip install pytest-run-parallel
# In your test file:
import pytest
def test_example():
assert True
# Run with: pytest --parallel-threads=4 test_example.py
Requires Python 3.10 or later. Pytest itself is not thread-safe; tests must be designed to handle shared state across threads, and fixtures like tmp_path are patched but stateful fixtures remain shared.
Verify before relying
- Whether psutil optional dependency is automatically detected or must be explicitly installed for CPU core detection
- Actual performance gains or overhead compared to serial execution for typical test suites
- Compatibility with other pytest plugins beyond xdist
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | actively maintained — 10 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 230,523/month — #9,106 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_run_parallel-0.10.0-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-raceProvides a pytest fixture that runs test…
permissive · top 15,000 on PyPI
pytest-threadleakA pytest plugin that detects when tests leak…
permissive · top 15,000 on PyPI
pytest-trioA pytest plugin that enables testing of async…
permissive · top 15,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
pytest-reraiseCaptures exceptions raised in threads during…
permissive · top 15,000 on PyPI
pytest-mpiA pytest plugin that marks and runs tests under…
permissive · top 15,000 on PyPI
pytest-timeoutAborts pytest tests that exceed a specified…
permissive · top 1,000 on PyPI
pytest-shardDistributes pytest test execution across…
permissive · top 5,000 on PyPI
pytest-twistedA pytest plugin that enables testing of…
permissive · top 15,000 on PyPI
pytest-socketA pytest plugin that blocks or restricts socket…
permissive · top 5,000 on PyPI