pytest-race
Race conditions tester for pytest
What it is and what it does
pytest-race is a pytest plugin that adds a `start_race` fixture for testing code that may have race conditions. It runs a test function concurrently in multiple threads and checks whether the code behaves correctly under concurrent access. The fixture accepts a thread count and a test callable, then executes that callable in parallel threads to expose timing-dependent bugs.
The package has no runtime dependencies beyond pytest itself, making it lightweight to add to a test suite. However, it has been abandoned since 2022, so compatibility with modern pytest and Python versions is uncertain. The approach of using threads to surface race conditions is inherently probabilistic—bugs may not always manifest in a single test run.
Use it for:
- Verify that global state or shared variables are protected against concurrent modification in multi-threaded code.
- Test thread-safe implementations of caches, counters, or other mutable objects accessed from multiple threads.
- Detect data corruption or assertion failures that occur only under concurrent access patterns.
- Validate that locks or synchronization primitives are correctly placed in critical sections.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a pytest fixture that runs test functions concurrently in multiple threads to detect race conditions in your code.
Yes, if you need to test for race conditions in a pytest suite and are willing to accept the maintenance risk. The package is simple, has no dependencies, and works for its stated purpose. However, verify compatibility with your pytest and Python versions first, since the project is no longer maintained.
Install
pytest-race on PyPI
pip
pip install pytest-raceuv
uv add pytest-racepoetry
poetry add pytest-raceInstalling pytest-race
Before you install
Installation is straightforward with no runtime dependencies. However, the project is abandoned—last updated in 2022 with no recent maintenance, so compatibility with newer versions is uncertain.
License in practice
BSD 3-Clause License is permissive and poses no restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
pip install pytest-race
from time import sleep
def test_race(start_race):
def actual_test():
global ACCUMULATOR
ACCUMULATOR += 1
assert ACCUMULATOR > 0
start_race(threads_num=2, target=actual_test)
Requires Python 3.7+ and pytest 2.9.0+
Verify before relying
- Whether the fixture works reliably with current pytest versions (last tested in 2022)
- Whether the threading approach reliably surfaces race conditions or if timing-dependent tests may be flaky
Package facts
| License | BSD 3-Clause License (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,529 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 792,803/month — #5,044 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_race-0.2.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-run-parallelA pytest plugin that runs test functions…
permissive · top 15,000 on PyPI
pytest-reraiseCaptures exceptions raised in threads during…
permissive · top 15,000 on PyPI
busypieProvides expressive, fluent API for…
permissive · top 15,000 on PyPI
pytest-asyncio-concurrentA pytest plugin that executes async test…
permissive · top 15,000 on PyPI
pytest-threadleakA pytest plugin that detects when tests leak…
permissive · top 15,000 on PyPI
pytest-httpbinProvides a pytest fixture that runs a local…
permissive · top 15,000 on PyPI
pytest-replayA pytest plugin that records test execution…
permissive · top 15,000 on PyPI
pytest-runtime-xfailA pytest plugin that provides a `runtime_xfail`…
permissive · top 15,000 on PyPI
pytest-fail-slowA pytest plugin that marks tests as failed if…
permissive · top 15,000 on PyPI
cosmic-rayCosmic Ray is a mutation testing tool that…
permissive · top 15,000 on PyPI