pytest-forked
run tests in isolated forked subprocesses
What it is and what it does
pytest-forked is a pytest plugin that isolates each test by running it in a forked subprocess. This allows tests involving C or C++ libraries—or any code prone to crashing—to fail gracefully without terminating the entire test run. A segfault or process death in one test does not affect subsequent tests.
The plugin is extracted from pytest-xdist's --forked module and can be used standalone with the --forked CLI flag, applied per-test via the @pytest.mark.forked decorator, or combined with pytest-xdist's parallel execution (e.g., pytest -n3 --forked) to run multiple test subprocesses in parallel, each forking individual tests. It is not available on Windows due to the absence of fork() support.
Use it for:
- Testing C/C++ bindings or extension modules that may crash the Python interpreter.
- Running tests with monkey-patched global state that could leak between tests.
- Detecting and reporting segfaults as test failures rather than suite termination.
- Combining with pytest-xdist to parallelize tests while isolating crash-prone code.
- Validating cleanup and teardown in tests that modify process-level state.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that runs each test in a forked subprocess to isolate crashes and segfaults, preventing a single test failure from terminating the entire test suite.
Yes, if you test C/C++ libraries or crash-prone code on POSIX systems. The low install friction and active maintenance make it a straightforward addition to test suites that need crash isolation. Not applicable on Windows. The inactive status means minimal new features, but the core functionality is stable and the plugin remains functional.
Install
pytest-forked on PyPI
pip
pip install pytest-forkeduv
uv add pytest-forkedpoetry
poetry add pytest-forkedInstalling pytest-forked
Before you install
Low friction install with a single runtime dependency on pytest. Actively maintained as of the latest release; however, the package is classified as Development Status 7 - Inactive, indicating minimal ongoing feature work.
License in practice
MIT license permits commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install pytest-forked
pytest --forked
# Or mark individual tests:
@pytest.mark.forked
def test_with_leaky_state():
pass
Does not work on Windows; requires a POSIX system with fork() support (Linux, macOS). Requires Python 3.10 or later.
Verify before relying
- Whether the plugin works correctly with pytest-xdist in all configurations beyond the documented -n3 --forked example.
- Performance overhead of forking per test compared to in-process execution.
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 — 6 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,263,193/month — #1,761 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_forked-1.7.5-py3-none-any.whl
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-subprocessPytest plugin that intercepts and fakes…
permissive · top 15,000 on PyPI
pytest-xprocesspytest-xprocess manages external processes…
permissive · top 15,000 on PyPI
pytest-rerunfailuresA pytest plugin that automatically reruns…
copyleft · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
pytest-flakefinderA pytest plugin that runs tests multiple times…
permissive · top 5,000 on PyPI
pytest-replayA pytest plugin that records test execution…
permissive · top 15,000 on PyPI
coverage_enable_subprocessInstalls a .pth file that automatically enables…
permissive · top 15,000 on PyPI
pytest-parallelA pytest plugin that runs tests in parallel…
permissive · top 15,000 on PyPI
pydantic-montyProvides Python bindings to execute untrusted…
permissive · top 5,000 on PyPI
isolateIsolate manages isolated Python environments…
unclear · top 15,000 on PyPI