pytest-xdist

Distribute pytest test runs across multiple CPUs and hosts to cut suite runtime

Tool
PyPI
v3.8.0
1,896stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
81/100Excellent
Development Activity80
Maintenance60
Community84
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture80
Code Quality82
Innovation76
Learning Curve78

pytest-xdist is the standard pytest plugin for parallelizing test execution. Running pytest -n auto spawns one worker process per available CPU core and distributes the collected tests across them, turning a slow single-threaded suite into one that finishes in a fraction of the time. Beyond simple load distribution, it supports several distribution modes (by test, by file, by test class/scope, or manual grouping) so suites with shared fixtures or stateful tests can still be split safely.

Beyond local multi-core speedups, pytest-xdist also supports distributing tests across multiple remote hosts over SSH or a custom rsync setup, and includes a loop-on-failure mode that reruns only the tests that failed on every file save. It has been part of the pytest ecosystem for over a decade and is maintained under the pytest-dev GitHub organization alongside pytest itself.

What You Get

  • The -n auto / -n <N> CLI flags to run tests across N worker processes automatically sized to available CPUs
  • Multiple distribution algorithms (load, loadscope, loadfile, loadgroup, worksteal, each) for balancing work while respecting fixture scope
  • Remote/distributed test execution across multiple machines via SSH, rsync, or a custom setup
  • A loop-on-failure mode (--looponfail) that reruns only failed tests automatically on file changes
  • Boxed/each mode to run the same test session against multiple Python interpreters or environments in one invocation

Common Use Cases

  • Speeding up large CI test suites by running them across all available CPU cores instead of serially
  • Splitting a slow integration/e2e suite across several worker processes while keeping tests that share a fixture scope on the same worker via loadscope
  • Running a test suite against multiple Python versions or environments in a single command using multi-interpreter distribution
  • Fast local development feedback loops using --looponfail to rerun only failing tests as files change

Under The Hood

Architecture - pytest-xdist implements a controller/worker model on top of execnet: the main pytest process (the DSession in dsession.py) collects tests, then spawns worker subprocesses (remote.py) that each import pytest and execute an assigned slice of the test IDs, streaming results back over an execnet gateway. workermanage.py tracks worker lifecycle (spawn, restart on crash, shutdown), while the scheduler/ package (load.py, loadscope.py, loadfile.py, loadgroup.py, worksteal.py, each.py) implements pluggable algorithms for deciding which test IDs go to which worker, so parallelism can be traded off against fixture-scope safety. looponfail.py layers a file-watching rerun loop on top of the same worker infrastructure. Tech Stack - Pure Python, built entirely as a pytest plugin registered via pytest11 entry points (xdist.plugin, xdist.looponfail); its only runtime dependencies are execnet>=2.1 for inter-process communication and pytest>=7.0, with filelock, psutil, and setproctitle as optional extras used for coordination and process naming. Packaging uses setuptools with setuptools-scm for version derivation from git tags. Code Quality - The testing/ directory contains a substantial suite (test_dsession.py, test_workermanage.py, test_remote.py, test_looponfail.py, test_newhooks.py, test_plugin.py) exercising the controller/worker protocol, scheduling logic, and CLI option parsing; the project uses type hints throughout (from __future__ import annotations, TYPE_CHECKING imports) and enforces black formatting. Error handling favors explicit warnings.warn for recoverable misconfiguration (e.g. invalid PYTEST_XDIST_AUTO_NUM_WORKERS values) over silent failure. API Design - The plugin’s public surface is a small set of well-documented CLI flags (-n, --dist, --tx, --looponfail) rather than an importable API, which keeps day-to-day usage to a one-line change in CI config; the custom pytest hooks it exposes (newhooks.py) are intended for advanced users writing their own distribution logic and are clearly separated from the common-path flags.

Used by 19 apps in this directory

Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
Python
68%
Other

AutoGPT

Automation · Productivity · AI Assistants

186,687

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
67
Dependency
Built with
Python68%
TypeScript31%
Updated today
Python
79%
Apache 2.0

changedetection.io

Monitoring

33,241

Self-hosted website change detection with AI-powered smart alerts, browser automation, price tracking, and 85+ notification channels.

View details
90
Repo Health
80
Technical
69
Dependency
Built with
Python79%
Updated 3 days ago
C++
69%
Apache 2.0

ClickHouse

Databases · Analytics · Data Engineering

49,325

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
C++69%
Python13%
Updated today
Python
51%
MIT

Docs

File Storage · CMS

16,733

Open-source collaborative knowledge platform with real-time editing, AI writing tools, and full self-hosting control — built by the French and German governments.

View details
87
Repo Health
81
Technical
72
Dependency
Built with
Python51%
TypeScript42%
Updated 2 days ago
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,761

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
67
Dependency
Built with
TypeScript75%
Updated today
Python
64%
BSD 3

Flagsmith

Developer Tools · Devops · Ab Testing Experimentation

6,518

Open-source feature flagging, remote config, and A/B/multivariate testing platform for web, mobile, and server-side apps — self-host or use the hosted SaaS.

View details
91
Repo Health
82
Technical
65
Dependency
Built with
Python64%
TypeScript31%
Updated today
Go
84%
MIT

Hatchet

AI Development · Developer Tools · Automation

7,749

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
69
Dependency
Built with
Go84%
PLpgSQL11%
Updated today
Python
63%
Other

Keep

Devops · Automation · Monitoring

12,224

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
91
Repo Health
79
Technical
67
Dependency
Built with
Python63%
TypeScript36%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search