Getting Started
Installation
pip install pytest-concurrency
Basic Usage
Enable Parallel Execution
# Run with 4 workers
pytest --workers 4
# Auto-detect CPU count
pytest --workers auto
Environment Variables
You can also configure workers via environment variable:
PYTEST_CONCURRENCY_WORKERS=4 pytest
How It Works
When --workers is provided or PYTEST_CONCURRENCY_WORKERS is set, the plugin:
- Patches pytest internals — makes
SetupState,FixtureDef, andos.environthread-local - Collects all tests — standard pytest collection
- Groups parametrized tests — keeps same test function with different params together
- Distributes across workers — round-robin assignment for balanced load
- Runs in parallel threads — each worker executes its test suite
Compatibility
- Python 3.10+
- pytest 7.0+
- Optional:
allure-pytestfor Allure integration
Limitations
- Tests must be thread-safe (no shared mutable state)
- Fixtures should not rely on process-level state
- Some pytest plugins may be incompatible with threading