Skip to content

Enable parallel pytest execution by default via pytest-xdist#399

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/enable-parallel-pytest-execution
Closed

Enable parallel pytest execution by default via pytest-xdist#399
Copilot wants to merge 2 commits intomainfrom
copilot/enable-parallel-pytest-execution

Conversation

Copy link

Copilot AI commented Feb 20, 2026

Tests ran sequentially despite pytest-xdist already being a dev dependency. This adds -n auto as the default addopts and wires up a proper CI test workflow.

Changes

  • pyproject.toml — Adds [tool.pytest.ini_options] with addopts = "-n auto", making parallel execution the default for all pytest invocations without requiring any flag
  • README.md — Updates testing section to use uv run pytest consistently 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 to main using uv sync --all-extras + uv run pytest tests/ -n auto -v; scoped to contents: read
[tool.pytest.ini_options]
addopts = "-n auto"
Original prompt

This section details on the original issue you should resolve

<issue_title>[Code Quality] Enable parallel pytest execution to speed up test suite</issue_title>
<issue_description>### Description

The test suite (18 files, 5,358 lines) runs sequentially, taking longer than necessary. Enabling parallel execution with pytest-xdist can significantly reduce test execution time.

Problem

From the Performance Research discussion (#219):

  • Tests run sequentially without parallelization
  • Identified as high-priority optimization (Week 1-2)
  • Target: Speed up test execution by 40%
  • pytest-xdist not currently used despite being in dev dependencies

Current State

Tests run with: uv run pytest tests/

No parallel execution configured.

Suggested Changes

  1. Update test execution command to use parallel workers:

    uv run pytest tests/ -n auto

    The -n auto flag automatically uses CPU count for optimal parallelization

  2. Add pytest-xdist to dev dependencies (if not already present):

    [project.optional-dependencies]
    dev = [
        "pytest>=8.3.4",
        "pytest-xdist>=3.6.1",  # Add this
        "pytest-mock>=3.14.0"
    ]
  3. Update documentation:

    • README.md test execution examples: uv run pytest tests/ -n auto
    • CI workflow test commands: uv run pytest tests/ -n auto -v
  4. Configure pytest.ini for parallel-safe settings:

    [tool.pytest.ini_options]
    addopts = "-n auto"

Files Affected

  • pyproject.toml (add pytest-xdist dependency if missing)
  • README.md (update test execution examples)
  • Future test.yml workflow (use -n auto flag)
  • .github/actions/*/build-steps/action.yml (update test commands)

Success Criteria

  • ✅ Test suite completes 30-40% faster with parallel execution
  • ✅ All tests remain stable and pass with parallelization
  • ✅ No race conditions or test isolation issues
  • ✅ CI workflows use parallel execution
  • ✅ Local development workflow benefits from faster tests

Priority

High - High-priority Week 1-2 optimization with significant time savings

Effort Estimate

20 minutes (add dependency, update commands, verify no race conditions)

Implementation Notes

Test isolation checks:

  • Ensure tests don't share global state
  • Verify mock isolation between parallel tests
  • Check that file I/O tests use unique temp paths
  • Validate thread-safe operations in tests

Performance measurement:

  • Measure baseline: time uv run pytest tests/
  • Measure parallel: time uv run pytest tests/ -n auto
  • Document speedup in PR description

Source

Extracted from Daily Perf Improver discussion abhimehro/ctrld-sync#219 - High Priority Week 1-2 optimization

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent

To install this workflow, run gh aw add github/gh-aw/.github/workflows/discussion-task-miner.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4. View source at https://github.com/github/gh-aw/tree/94662b1dee8ce96c876ba9f33b3ab8be32de82a4/.github/workflows/discussion-task-miner.md.

  • expires on Feb 20, 2026, 5:44 AM UTC

Comments on the Issue (you are @copilot in this section)

Custom agent used: Development Partner
The Development Partner Protocol


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@trunk-io
Copy link

trunk-io bot commented Feb 20, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
Copilot AI changed the title [WIP] Enable parallel pytest execution to speed up test suite Enable parallel pytest execution by default via pytest-xdist Feb 20, 2026
Copilot AI requested a review from abhimehro February 20, 2026 03:42
@abhimehro abhimehro marked this pull request as ready for review February 22, 2026 10:09
Copilot AI review requested due to automatic review settings February 22, 2026 10:09
@github-actions github-actions bot added documentation Improvements or additions to documentation python configuration labels Feb 22, 2026
@github-actions
Copy link

👋 Development Partner is reviewing this PR. Will provide feedback shortly.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] with addopts = "-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.yml CI 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
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
run: uv run pytest tests/ -n auto -v
run: uv run pytest tests/ -v

Copilot uses AI. Check for mistakes.
Comment on lines +138 to +141
**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
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@abhimehro
Copy link
Owner

Closing: duplicate of #406, both fail CI. Consolidate if feature desired.

@abhimehro abhimehro closed this Feb 28, 2026
@abhimehro abhimehro deleted the copilot/enable-parallel-pytest-execution branch March 2, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Quality] Enable parallel pytest execution to speed up test suite

3 participants