Add dedicated test workflow with parallel pytest execution#405
Add dedicated test workflow with parallel pytest execution#405
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 creates a dedicated test workflow to automatically run pytest tests on PRs and pushes to main, addressing a gap where the repository had pytest-xdist configured but no CI workflow to leverage it.
Changes:
- Adds
.github/workflows/test.ymlto run tests automatically on push/PR with parallel execution via pytest-xdist - Adds pytest configuration to
pyproject.tomlto centralize test discovery patterns and default options
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
.github/workflows/test.yml |
New CI workflow that runs pytest with parallel execution (-n auto) on push to main, pull requests, and manual dispatch |
pyproject.toml |
Adds [tool.pytest.ini_options] section with test discovery patterns and default options (-v --strict-markers) |
| # PERFORMANCE: Cache pip dependencies to speed up CI runs | ||
| # Cache key is based on pyproject.toml hash since dev deps are defined there | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.13' | ||
| cache: 'pip' | ||
| cache-dependency-path: 'pyproject.toml' | ||
|
|
||
| # Install the package with dev dependencies (pytest, pytest-mock, pytest-xdist) | ||
| - name: Install dependencies | ||
| run: pip install -e ".[dev]" | ||
|
|
||
| # PERFORMANCE: -n auto enables parallel execution via pytest-xdist, | ||
| # distributing tests across available CPU cores for 40%+ faster runs | ||
| - name: Run tests | ||
| run: pytest tests/ -n auto |
There was a problem hiding this comment.
The workflow uses pip for dependency installation, but the repository has a uv.lock file and the performance.yml workflow uses uv (astral-sh/setup-uv@v4 + uv sync --all-extras). For consistency with the existing performance workflow and to ensure deterministic builds using the lockfile, this workflow should also use uv. Replace the setup-python caching and pip install steps with uv installation and sync, similar to performance.yml lines 19-30.
| # PERFORMANCE: Cache pip dependencies to speed up CI runs | |
| # Cache key is based on pyproject.toml hash since dev deps are defined there | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| cache: 'pip' | |
| cache-dependency-path: 'pyproject.toml' | |
| # Install the package with dev dependencies (pytest, pytest-mock, pytest-xdist) | |
| - name: Install dependencies | |
| run: pip install -e ".[dev]" | |
| # PERFORMANCE: -n auto enables parallel execution via pytest-xdist, | |
| # distributing tests across available CPU cores for 40%+ faster runs | |
| - name: Run tests | |
| run: pytest tests/ -n auto | |
| # Set up Python and uv; uv will manage dependencies via the lockfile | |
| - name: Set up Python with uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| python-version: '3.13' | |
| # Install the package and dependencies using uv and the uv.lock file | |
| # Using --all-extras keeps behavior consistent with installing extras via pip | |
| - name: Install dependencies | |
| run: uv sync --all-extras | |
| # PERFORMANCE: -n auto enables parallel execution via pytest-xdist, | |
| # distributing tests across available CPU cores for 40%+ faster runs | |
| - name: Run tests | |
| run: uv run pytest tests/ -n auto |
| testpaths = ["tests"] | ||
| python_files = "test_*.py" | ||
| python_functions = "test_*" | ||
| addopts = "-v --strict-markers" |
There was a problem hiding this comment.
For consistency and to ensure all pytest invocations benefit from parallel execution (not just CI runs), consider adding "-n auto" to the addopts configuration. This ensures developers running pytest locally and other workflows also get parallel execution by default. Suggested: addopts = "-n auto -v --strict-markers". This aligns with the performance optimization goal mentioned in the PR description and follows the pattern where configuration is centralized in pyproject.toml.
| addopts = "-v --strict-markers" | |
| addopts = "-n auto -v --strict-markers" |
No CI workflow existed to run tests on PRs/pushes, leaving
pytest-xdist(already a dev dependency) unused and PRs unvalidated automatically.Changes
.github/workflows/test.yml(new): Runs onpushtomain,pull_request, andworkflow_dispatch. Uses Python 3.13, pip cache keyed onpyproject.toml, installs viapip install -e ".[dev]", and executespytest tests/ -n autofor parallel distribution across available CPU cores. Scoped topermissions: contents: read.pyproject.toml: Adds[tool.pytest.ini_options]— setstestpaths, discovery patterns, andaddopts = "-v --strict-markers"so verbosity and strict markers apply globally without repeating flags per invocation.Original 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.