Enable parallel pytest execution with pytest-xdist by default#406
Enable parallel pytest execution with pytest-xdist by default#406
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 consolidates multiple duplicate issues (#319, #324, #307, #314, #332, #356) into a single implementation that enables parallel pytest execution using pytest-xdist by default. The changes make test execution faster by distributing tests across all available CPU cores automatically, without requiring developers to remember command-line flags.
Changes:
- Adds default parallel execution configuration to pytest via pyproject.toml
- Creates new CI workflow for automated testing on push/PR to main branch
- Updates documentation to reflect parallel-by-default behavior and provides escape hatch for sequential runs
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pyproject.toml | Adds [tool.pytest.ini_options] with addopts = "-n auto" to enable parallel execution by default |
| .github/workflows/test.yml | New CI workflow that runs tests on push/PR to main using pytest with parallel execution |
| README.md | Consolidates test documentation to reflect parallel-by-default behavior, removes redundant sections, documents -n0 flag for sequential execution override |
| - name: Install dependencies | ||
| run: pip install httpx python-dotenv pytest pytest-mock pytest-xdist | ||
|
|
||
| - name: Run tests in parallel | ||
| run: pytest tests/ -n auto -v |
There was a problem hiding this comment.
The dependency installation approach is inconsistent with other workflows in this repository. The sync.yml workflow uses pip with caching enabled (via setup-python's cache parameter), while performance.yml uses the modern uv package manager with built-in caching. This test.yml workflow uses pip without any caching, which will result in slower CI runs.
Recommend aligning with the performance.yml pattern by using uv:
- Add a step to install uv using astral-sh/setup-uv@v4 with enable-cache: true
- Replace the pip install command with "uv sync --all-extras"
- Update the test command to "uv run pytest tests/ -n auto -v"
This approach provides better caching, faster dependency resolution, and consistency with the modern tooling already established in performance.yml.
| - name: Install dependencies | |
| run: pip install httpx python-dotenv pytest pytest-mock pytest-xdist | |
| - name: Run tests in parallel | |
| run: pytest tests/ -n auto -v | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --all-extras | |
| - name: Run tests in parallel | |
| run: uv run pytest tests/ -n auto -v |
| run: pip install httpx python-dotenv pytest pytest-mock pytest-xdist | ||
|
|
||
| - name: Run tests in parallel | ||
| run: pytest tests/ -n auto -v |
There was a problem hiding this comment.
The explicit "-n auto" flag in the pytest command is now redundant since pyproject.toml already sets "addopts = -n auto" by default. While harmless, this duplication could cause confusion if someone later tries to modify the parallelization behavior—they would need to remember to update both locations.
Consider simplifying to "pytest tests/ -v" (or "uv run pytest tests/ -v" if switching to uv) and let the pyproject.toml configuration handle the parallelization. This reduces duplication and makes the configuration more maintainable.
| run: pytest tests/ -n auto -v | |
| run: pytest tests/ -v |
| # Install dev dependencies first | ||
| pip install pytest pytest-mock pytest-xdist |
There was a problem hiding this comment.
The documentation shows installing dev dependencies with pip, but this is inconsistent with the modern tooling pattern established in the repository. The repository has uv.lock and performance.yml uses "uv sync --all-extras" for dependency installation.
Consider updating the documentation to recommend the uv approach for consistency:
# Install dev dependencies first
uv sync --all-extrasAlternatively, if pip is the intended approach for local development, document both options with a note about which is preferred.
| # Install dev dependencies first | |
| pip install pytest pytest-mock pytest-xdist | |
| # Install dev dependencies first (uses uv for consistency with CI/tooling) | |
| uv sync --all-extras |
|
Closing: duplicate of parallel pytest work (#399 also fails CI). Consolidate if feature desired. |
Multiple duplicate issues tracked the same unimplemented feature: parallel test execution via pytest-xdist. This PR implements the canonical solution and adds CI enforcement.
Changes
pyproject.toml— adds[tool.pytest.ini_options]withaddopts = "-n auto"so every barepytestinvocation automatically distributes across all CPU cores; no per-invocation flag required.github/workflows/test.yml— new CI workflow (push/PR tomain) that installs deps and runspytest tests/ -n auto -v; usespermissions: contents: read(least privilege)README.md— consolidates the "basic" and "parallel (recommended)" test sections into one, documents-n0as the escape hatch for sequential runsOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.