Enable parallel pytest execution by default via pytest-xdist#399
Enable parallel pytest execution by default via pytest-xdist#399
Conversation
|
Merging to
|
Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
|
👋 Development Partner is reviewing this PR. Will provide feedback shortly. |
There was a problem hiding this comment.
Pull request overview
This PR enables parallel test execution by default using pytest-xdist, addressing a high-priority performance optimization. The changes configure pytest to automatically use all available CPU cores via the -n auto flag, eliminating the need to pass this flag manually. A new CI workflow is introduced to ensure tests run in parallel in GitHub Actions.
Changes:
- Adds
[tool.pytest.ini_options]withaddopts = "-n auto"to enable parallel test execution by default - Updates README.md documentation to reflect parallel execution as the default and migrate all examples to use
uv run pytest - Introduces
.github/workflows/test.ymlCI workflow for automated testing on push/PR to main
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pyproject.toml | Adds pytest configuration to enable parallel execution by default via -n auto in addopts |
| README.md | Updates testing documentation to show parallel execution is default, standardizes on uv run pytest commands |
| .github/workflows/test.yml | New CI workflow using uv for dependency management and running parallel tests on push/PR |
| run: uv sync --all-extras | ||
|
|
||
| - name: Run tests | ||
| run: uv run pytest tests/ -n auto -v |
There was a problem hiding this comment.
The -n auto flag is redundant here since it's already configured as the default in pyproject.toml via addopts = "-n auto". Consider removing -n auto from this command to avoid duplication and rely on the centralized configuration. This makes the pytest configuration easier to maintain in one place.
| run: uv run pytest tests/ -n auto -v | |
| run: uv run pytest tests/ -v |
| **Parallel test execution:** | ||
| ```bash | ||
| # Run tests in parallel using all available CPU cores | ||
| pytest tests/ -n auto | ||
| # Run tests in parallel using all available CPU cores (default via addopts) | ||
| uv run pytest tests/ -n auto |
There was a problem hiding this comment.
The comment states "uses -n auto by default via pyproject.toml" which is accurate, but then the example command explicitly includes -n auto again. This is redundant since running uv run pytest tests/ (without -n auto) will already use parallel execution due to the addopts configuration. Consider updating the comment to clarify that the flag is optional/redundant here, or remove the -n auto from the example to demonstrate relying on the default configuration.
|
Closing: duplicate of #406, both fail CI. Consolidate if feature desired. |
Tests ran sequentially despite
pytest-xdistalready being a dev dependency. This adds-n autoas the defaultaddoptsand wires up a proper CI test workflow.Changes
pyproject.toml— Adds[tool.pytest.ini_options]withaddopts = "-n auto", making parallel execution the default for allpytestinvocations without requiring any flagREADME.md— Updates testing section to useuv run pytestconsistently and reflects that parallel execution is now the default (removes the stale note suggesting it might be slower).github/workflows/test.yml(new) — CI workflow on push/PR tomainusinguv sync --all-extras+uv run pytest tests/ -n auto -v; scoped tocontents: readOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.