-
Notifications
You must be signed in to change notification settings - Fork 1
Enable parallel pytest execution by default via pytest-xdist #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up uv | ||
| uses: astral-sh/setup-uv@v4 | ||
|
|
||
| - name: Set up Python | ||
| run: uv python install 3.13 | ||
|
|
||
| - name: Install dependencies | ||
| run: uv sync --all-extras | ||
|
|
||
| - name: Run tests | ||
| run: uv run pytest tests/ -n auto -v | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,41 +126,41 @@ This project includes a comprehensive test suite to ensure code quality and corr | |
|
|
||
| ### Running Tests | ||
|
|
||
| **Basic test execution:** | ||
| **Basic test execution (parallel by default):** | ||
| ```bash | ||
| # Install dev dependencies first | ||
| pip install pytest pytest-mock pytest-xdist | ||
| uv sync --all-extras | ||
|
|
||
| # Run all tests | ||
| pytest tests/ | ||
| # Run all tests (uses -n auto by default via pyproject.toml) | ||
| uv run pytest tests/ | ||
| ``` | ||
|
|
||
| **Parallel test execution (recommended):** | ||
| **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 | ||
|
Comment on lines
+138
to
+141
|
||
|
|
||
| # Run with specific number of workers | ||
| pytest tests/ -n 4 | ||
| uv run pytest tests/ -n 4 | ||
| ``` | ||
|
|
||
| **Note on parallel execution:** The test suite is currently small (~78 tests, <1s execution time), so parallel execution overhead may result in longer wall-clock time compared to sequential execution. However, pytest-xdist is included for: | ||
| **Note on parallel execution:** Parallel execution is configured as the default via `addopts = "-n auto"` in `pyproject.toml`. pytest-xdist provides: | ||
| - **Test isolation verification** - Ensures tests don't share state | ||
| - **Future scalability** - As the test suite grows, parallel execution will provide significant speedups | ||
| - **CI optimization** - May benefit from parallelization in CI environments with different characteristics | ||
| - **Faster CI runs** - Parallel execution reduces test suite time, especially as the suite grows | ||
| - **Scalability** - As the test suite grows, parallelization provides increasing speedups | ||
|
|
||
| ### Development Workflow | ||
|
|
||
| For active development with frequent test runs: | ||
| ```bash | ||
| # Run tests sequentially (faster for small test suites) | ||
| pytest tests/ -v | ||
| # Run tests in parallel (default) | ||
| uv run pytest tests/ -v | ||
|
|
||
| # Run specific test file | ||
| pytest tests/test_security.py -v | ||
| uv run pytest tests/test_security.py -v | ||
|
|
||
| # Run tests matching pattern | ||
| pytest tests/ -k "test_validation" -v | ||
| uv run pytest tests/ -k "test_validation" -v | ||
| ``` | ||
|
|
||
| ## Release Process | ||
|
|
@@ -170,7 +170,7 @@ This project uses manual releases via GitHub Releases. To create a new release: | |
| 1. **Ensure all changes are tested and merged to `main`** | ||
| ```bash | ||
| # Verify tests pass | ||
| pytest tests/ | ||
| uv run pytest tests/ | ||
|
|
||
| # Verify security scans pass | ||
| bandit -r main.py -ll | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,6 @@ dev = [ | |
| "pytest-xdist>=3.0.0", | ||
| "pytest-benchmark>=4.0.0", | ||
| ] | ||
|
|
||
| [tool.pytest.ini_options] | ||
| addopts = "-n auto" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
-n autoflag is redundant here since it's already configured as the default inpyproject.tomlviaaddopts = "-n auto". Consider removing-n autofrom this command to avoid duplication and rely on the centralized configuration. This makes the pytest configuration easier to maintain in one place.