pytest-parallel is a pytest plugin that enables parallel and concurrent testing by utilizing both multiprocessing (workers) and multithreading (tests per worker). It is designed for specific use cases, such as Selenium tests, where tests can be thread-safe, benefit from non-blocking I/O, and manage minimal state in the Python environment. It is not intended as a direct replacement for pytest-xdist, which focuses solely on process-based parallelism for general test distribution. The current version is 0.1.1. The project appears to be unmaintained.
pip install pytest-parallelNo compatibility data collected yet for this library.
Create a test file (e.g., `test_example.py`) and then execute pytest from your terminal, specifying the number of workers (processes) and tests per worker (concurrent threads). This example demonstrates how to set up simple tests for parallel and concurrent execution.
Consider alternatives like pytest-xdist for general parallel execution, or thoroughly test pytest-parallel's compatibility with your specific pytest version before relying on it in production. Be aware that the `pytest-run-parallel` project (from Quansight-Labs) is a different, more actively maintained project with a similar goal, but distinct features.
Monitor for unexpected crashes or hangs in parallel test runs on macOS. You may need to investigate alternative multiprocessing start methods or adjust your test environment if issues arise, though direct control over this within `pytest-parallel` is not explicitly documented.
Ensure all tests are atomic, independent, and properly isolated. Avoid shared mutable state between tests. If a test is not thread-safe, it should not be run concurrently. Consider marking such tests to run serially if your test suite design cannot guarantee thread safety.
Profile your test suite's execution time with and without `pytest-parallel`. Use it primarily for I/O-bound tests (like web requests in Selenium) that can genuinely benefit from concurrency and parallelization, rather than CPU-bound unit tests.
Install pytest-parallel using `pip install pytest-parallel`. If already installed, ensure your pytest version is compatible (e.g., pytest-parallel 0.1.1 was developed for older pytest versions; `pytest < 7.0` is generally safer than recent ones).
Verify `pytest-parallel` is installed for the active Python environment (`pip install pytest-parallel`). If the warning persists, it might indicate an incompatibility; try creating a fresh virtual environment or downgrading your `pytest` version (e.g., `pip install "pytest<7"`).
Install the plugin using `pip install pytest-parallel`. Ensure you are using the correct Python virtual environment if you have multiple.