From d1b1b54ef3ed6bbfe162a13835ff4687d5530048 Mon Sep 17 00:00:00 2001 From: Phil LaFayette Date: Thu, 25 Jun 2026 22:05:07 -0500 Subject: [PATCH] Parallelize Python test suite with pytest-xdist (~31s -> ~12s wall) Add pytest-xdist to the dev dependency group and default the pytest run to '-n auto --dist=worksteal' so the 1526-test unit suite runs across all CPU cores instead of serially on one. The suite was already parallel-safe: every test that binds a real socket (test_mqtt_ws_bridge, test_doctor) uses an OS-assigned ephemeral port via socket.bind((host, 0)); the broker/publisher lifecycle tests fully mock amqtt/aiomqtt so no real ports are opened; and all filesystem and env state flows through per-test tmp_path / monkeypatch. Each xdist worker is its own process with its own tmp base, so 8 workers never collide. The fixed ports in conftest's tmp_config/e2e_config are config-dict values only and are never bound. worksteal rebalances pending tests onto idle workers, which matters because the textual TUI tests are much slower than the rest. CI's Test job runs plain 'pytest ...' with no addopts override, so it inherits -n auto automatically; pytest-xdist ships via the dev extra the job already installs ([all,dev]). Result: ~31s -> ~12s cold wall (2.6x), ~6-9s warm. 1526 passed, verified stable across 5 consecutive parallel runs (all exit 0). --- pyproject.toml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index e0f0044..e97a651 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,12 @@ all = ["claude-comms[tui,web]"] dev = [ "pytest>=7.0", "pytest-asyncio>=0.21", + # Parallelizes the unit-test suite across CPU cores. The suite is + # parallel-safe: every test that binds a real socket uses an + # OS-assigned ephemeral port, and all filesystem state goes through + # per-test ``tmp_path`` / ``monkeypatch`` (each xdist worker is its own + # process with its own tmp base), so 8 workers never collide. + "pytest-xdist>=3.0", ] [project.scripts] @@ -103,6 +109,13 @@ exclude = [ [tool.pytest.ini_options] testpaths = ["tests"] +# Run the suite in parallel across all CPU cores (pytest-xdist). The suite is +# parallel-safe (ephemeral ports + per-test tmp_path/monkeypatch state), so +# this is a pure wall-clock win with identical results. ``worksteal`` rebalances +# the queue so a worker that finishes its share picks up pending tests from +# busier workers — important because the textual TUI tests are much slower than +# the rest. Override locally with ``-n0`` to force serial (e.g. for a debugger). +addopts = "-n auto --dist=worksteal" # Targeted warning filters so `pytest -q` runs clean. Each entry silences a # SPECIFIC, understood category — not a blanket ignore — so a genuinely new # warning still surfaces.