Registry / testing / pytest-parallel

pytest-parallel

JSON →
library0.1.1pypypiunverified

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-parallel
INSTALL
IMPORT
SIG · PYTEST-PARALLEL
P
pytest-parallel
testingpythonv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.

import time import pytest # test_example.py def test_fast_operation_1(): time.sleep(0.01) assert True def test_fast_operation_2(): time.sleep(0.01) assert True def test_fast_operation_3(): time.sleep(0.01) assert True def test_slow_operation_1(): time.sleep(0.1) assert True def test_slow_operation_2(): time.sleep(0.1) assert True # Run with: pytest --workers 2 --tests-per-worker 2 # This will execute tests using 2 processes, with each process running up to 2 tests concurrently.
Debug
Known issues
breakingThe pytest-parallel project (version 0.1.1) is explicitly marked as unmaintained on its GitHub repository. It relies on patching pytest internals, which can lead to instability or breakage with newer versions of pytest as the internal structure changes.
fix
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.
affects: 0.1.1 and potentially future pytest versions
gotchaStarting with Python 3.8 on macOS, forking behavior for multiprocessing is forced at the expense of safety, and `spawn` is the default start method. Using `pytest-parallel` (which leverages multiprocessing) on macOS with Python 3.8+ might expose subprocess stability issues due to this change.
fix
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.
affects: 0.1.1 on macOS with Python 3.8+
gotchaParallel and concurrent testing with `pytest-parallel` requires careful test isolation. Tests that modify shared global state, rely on specific test ordering, or use non-thread-safe fixtures (e.g., `capsys`, `monkeypatch` as warned by similar plugins) will likely lead to flaky tests, unpredictable failures, or incorrect results.
fix
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.
affects: All versions
gotchaWhile `pytest-parallel` enables concurrent execution, it's not a universal speedup solution. For test suites consisting of many very fast unit tests that don't involve I/O waits, the overhead of managing processes and threads can sometimes make parallel execution slower than sequential execution.
fix
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.
affects: All versions
Errors
Common errors & fixes
pytest: error: unrecognized arguments: --workers=2
The pytest-parallel plugin is not correctly installed or loaded by pytest in the current environment, preventing pytest from recognizing its specific command-line options.
fix
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).
PytestWarning: Unknown pytest plugin module: 'pytest_parallel'
pytest failed to discover or load the pytest-parallel plugin, which can happen if the plugin's entry point is incorrectly configured, if it's installed for a different Python interpreter, or due to incompatibility with the pytest version.
fix
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"`).
ModuleNotFoundError: No module named 'pytest_parallel'
The pytest-parallel package is not installed in the Python environment from which you are trying to import it or run pytest.
fix
Install the plugin using `pip install pytest-parallel`. Ensure you are using the correct Python virtual environment if you have multiple.
Upgrade
Version history
0.1.1latest on PyPI · released Oct 10, 2021
Audit
Dependencies
pytestrequiredCore testing framework that this plugin extends.
Agent activity
3 hits · last 30 days
node
2
Resources
pytest-parallel — pip install pytest-parallel · libregistry