pytest-forked is a pytest plugin that runs tests in isolated forked subprocesses, preventing global state pollution and ensuring test independence. As of version 1.6.0, it supports modern Python (3.7+) and pytest versions, offering a crucial tool for test isolation. It generally follows pytest's release cadence for compatibility updates.
pip install pytest-forkedNo compatibility data collected yet for this library.
pytest-forked is typically activated via command-line arguments or `pytest.ini` configuration, not by direct Python imports. This example demonstrates how tests benefit from isolation when `--forked` is used, preventing global state changes in one test from affecting another.
Upgrade your Python environment to 3.7 or higher.
Ensure your pytest-forked and pytest versions are compatible. Refer to release notes on GitHub for specific version matrices. Generally, use the latest stable versions of both.
Re-initialize shared resources within each test, or use fixtures with `scope='function'` that are executed after the fork. Avoid opening global resources in `conftest.py` setup code if they are not fork-safe.
Upgrade to pytest-forked v1.2.0 or newer for improved `xfail` support. Thoroughly test `xfail` marked tests when using forked processes to confirm expected behavior.