Wall-clock time is the metric
If your test suite takes 30 minutes serial, splitting it across 6 parallel jobs brings the wall clock to ~5 minutes (plus a fixed checkout/install overhead per shard). On a paid runner pricing model, you spend the same minutes — but the developer waits 5 minutes instead of 30.
How to split tests
- By directory —
pytest tests/api/in one job,pytest tests/db/in another. - By marker —
pytest -m 'unit'vs-m 'integration'. - By auto-shard —
pytest-xdist --dist=loadgroup -n 4splits within a single runner; combine with matrix to split across runners. - By time-bucket — record per-test timing, group into buckets of equal duration.
pytest-splitdoes this.
Coordination challenges
- Each shard does its own install. Cache aggressively.
- Coverage reports must be merged across shards. Use
coverage combine. - Flaky tests are amplified by sharding — re-run only the failing shard.