pytest-xdist

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

Tool
PyPI
v3.8.0
1,924 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
84 /100 Excellent
Development Activity 88
Maintenance 64
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 80
Code Quality 82
Innovation 76
Learning Curve 78

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
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,802

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
62
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
TypeScript
39%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,540

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
64
Dependency
Built with
TypeScript 39%
JavaScript 27%
Python 25%
Updated 6 days ago
TypeScript
92%
Other

OpenHands

AI Code Assistants · AI Development

91,695

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 92%
Updated 6 days ago
TypeScript
39%
AGPL 3.0

OpenObserve

Analytics · Devops · Monitoring

22,475

Open source observability platform for logs, metrics, traces, and real user monitoring — delivering 140x lower storage costs than Elasticsearch with a single binary you can run in under 2 minutes.

View details
90
Repo Health
9
Technical
68
Dependency
Built with
TypeScript 39%
Rust 30%
Vue 17%
Updated 5 days ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 5 days ago
Rust
90%
Apache 2.0

Qdrant

AI Development · Databases · Search

35,220

Open-source vector database and search engine built in Rust for production-grade AI applications — from semantic search to RAG pipelines and recommendation systems.

View details
92
Repo Health
87
Technical
62
Dependency
Built with
Rust 90%
Updated 6 days ago
Python
99%
Apache 2.0

Rasa Open Source

AI Assistants · AI Development · Voice AI

21,353

Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.

View details
62
Repo Health
78
Technical
63
Dependency
Built with
Python 99%
Updated 3 months ago
Python
94%
BSD 3

skrub

Developer Tools

1,660

Turn messy real-world dataframes into machine learning features — no manual wrangling required.

View details
86
Repo Health
84
Technical
79
Dependency
Built with
Python 94%
Updated 1 weeks ago
C
74%
AGPL 3.0

TDengine

Databases

25,168

A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.

View details
97
Repo Health
71
Technical
65
Dependency
Built with
C 74%
C++ 19%
Updated 1 weeks ago

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