Skip to content

⚡ perf(test): parallelize test suite with pytest-xdist - #3035

Merged
gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:speed
Feb 15, 2026
Merged

⚡ perf(test): parallelize test suite with pytest-xdist#3035
gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:speed

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

The test suite runs all 420 tests serially, taking ~74s on a modern machine. For a project where CI runs across many Python versions, this adds up quickly. 🕐

This adds pytest-xdist and configures tox to run tests with -n auto --dist loadfile. The auto flag scales workers to available CPU cores, while loadfile keeps tests from the same file on the same worker so session-scoped fixtures (like activation_python which creates a shared venv) aren't needlessly recreated. The existing coverage infrastructure — coverage-enable-subprocess, COVERAGE_PROCESS_START, and coverage combine — already handles subprocess coverage collection, so no additional wiring was needed.

Also removes unnecessary pip seeding from test_create_long_path (it only validates long path support, not pip) and reduces the per-test timeout from 600s to 120s since the slowest test takes ~6s. ⚡ Wall-clock time drops from ~74s to ~26s with no change in test results or coverage.

The test suite ran serially at ~74s. Adding pytest-xdist with
`-n auto --dist loadfile` distributes tests across CPU cores while
keeping same-file tests together for efficient session-fixture reuse.

The existing coverage infrastructure (coverage-enable-subprocess,
COVERAGE_PROCESS_START, coverage combine) already handles subprocess
coverage, so no additional wiring was needed.

Also skip pip seeding in test_create_long_path since it only validates
long path support, and reduce the per-test timeout from 600s to 120s
since the slowest test takes ~6s.

Wall-clock time drops from ~74s to ~26s.
@gaborbernat
gaborbernat marked this pull request as ready for review February 15, 2026 16:24
@gaborbernat
gaborbernat enabled auto-merge (squash) February 15, 2026 16:24
@gaborbernat
gaborbernat merged commit 85470d6 into pypa:main Feb 15, 2026
51 checks passed
@gaborbernat
gaborbernat deleted the speed branch February 23, 2026 12:34
This was referenced Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant