Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

ci: run unit tests across all runner cores with pytest-xdist (#3098)

Raghav Chamadiyac6c61e894caa
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ea72a4d18..60bc1b66e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -45,14 +45,21 @@ jobs:
- name: Run provider tests (no API keys required)
run: uv run pytest tests/providers/ -v --tb=short
+ # One worker per core. loadfile keeps each module on one worker, so a
+ # module-scoped fixture (an indexed sample repo, say) is built once, not
+ # once per worker that draws a test from it.
- name: Run unit tests
if: matrix.python-version != '3.12'
- run: uv run pytest tests/unit/ -v --tb=short
+ run: uv run pytest tests/unit/ -n auto --dist loadfile -v --tb=short --durations=25
# One leg measures coverage for the pull request bot's checks comment.
+ # sysmon (Python 3.12+) measures lines with far less overhead than the
+ # tracer; it cannot record per-test contexts, which this report omits.
- name: Run unit tests with coverage
if: matrix.python-version == '3.12'
- run: uv run --with pytest-cov pytest tests/unit/ -v --tb=short --cov=packages --cov-report=xml
+ env:
+ COVERAGE_CORE: sysmon
+ run: uv run --with pytest-cov pytest tests/unit/ -n auto --dist loadfile -v --tb=short --durations=25 --cov=packages --cov-report=xml
- name: Upload coverage to Repowise
if: always() && matrix.python-version == '3.12'
diff --git a/pyproject.toml b/pyproject.toml
index 8b122f732..6197b05e9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -121,6 +121,7 @@ dev = [
"pytest>=8,<9",
"pytest-asyncio>=0.23,<1",
"pytest-snapshot>=0.9,<1",
+ "pytest-xdist>=3.5,<4",
"respx>=0.21,<1",
"time-machine>=2.14,<3",
"ruff>=0.6,<1",
@@ -183,6 +184,7 @@ dev = [
"pytest>=8,<9",
"pytest-asyncio>=0.23,<1",
"pytest-snapshot>=0.9,<1",
+ "pytest-xdist>=3.5,<4",
"respx>=0.21,<1",
"time-machine>=2.14,<3",
"ruff>=0.6,<1",
diff --git a/tests/unit/savings/test_pricing_snapshot.py b/tests/unit/savings/test_pricing_snapshot.py
index ce80d0dc5..625eb1e06 100644
--- a/tests/unit/savings/test_pricing_snapshot.py
+++ b/tests/unit/savings/test_pricing_snapshot.py
@@ -198,7 +198,12 @@ def test_a_stale_cache_is_rescanned(repo: Path, monkeypatch: pytest.MonkeyPatch)
json.dumps({"version": 1, "resolved_at": "yesterday", "model": "m"}),
json.dumps({"version": 1, "resolved_at": True, "model": "m"}),
json.dumps({"version": 1, "resolved_at": 0}), # epoch: older than any TTL
- json.dumps({"version": 1, "resolved_at": time.time(), "model": "m" * 129}),
+ # A fixed id: the timestamp differs per process, and xdist workers
+ # must collect identical test ids.
+ pytest.param(
+ json.dumps({"version": 1, "resolved_at": time.time(), "model": "m" * 129}),
+ id="overlong-model",
+ ),
json.dumps([1, 2, 3]),
],
)
diff --git a/tests/unit/server/mcp/test_answer_synthesis_timeout.py b/tests/unit/server/mcp/test_answer_synthesis_timeout.py
index 85726ced3..72f38685d 100644
--- a/tests/unit/server/mcp/test_answer_synthesis_timeout.py
+++ b/tests/unit/server/mcp/test_answer_synthesis_timeout.py
@@ -136,7 +136,12 @@ def test_an_effectively_unbounded_override_is_clamped(monkeypatch, huge):
assert _synthesis_timeout(_Provider(budget=180.0)) == _MAX_TIMEOUT_S
[email protected]("junk", ["abc", True, False, object(), -5, 0, float("nan")], ids=repr)
+# object()'s repr carries its address, which differs per xdist worker.
+ "junk",
+ ["abc", True, False, object(), -5, 0, float("nan")],
+ ids=lambda v: "object()" if type(v) is object else repr(v),
+)
def test_a_provider_declaring_junk_falls_back_instead_of_raising(junk):
"""The attribute belongs to a class that need not subclass BaseProvider.
diff --git a/uv.lock b/uv.lock
index ee477281e..eb0ea8cba 100644
--- a/uv.lock
+++ b/uv.lock
@@ -710,6 +710,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/55/e2/2537ebcff11c1ee1ff17d8d0b6f4db75873e3b0fb32c2d4a2ee31ecb310a/docstring_parser-0.17.0-py3-none-any.whl", hash = "sha256:cf2569abd23dce8099b300f9b4fa8191e9582dda731fd533daf54c4551658708", size = 36896, upload-time = "2025-07-21T07:35:00.684Z" },
]
+[[package]]
+name = "execnet"
+version = "2.1.2"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/bf/89/780e11f9588d9e7128a3f87788354c7946a9cbb1401ad38a48c4db9a4f07/execnet-2.1.2.tar.gz", hash = "sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd", size = 166622, upload-time = "2025-11-12T09:56:37.75Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ab/84/02fc1827e8cdded4aa65baef11296a9bbe595c474f0d6d758af082d849fd/execnet-2.1.2-py3-none-any.whl", hash = "sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec", size = 40708, upload-time = "2025-11-12T09:56:36.333Z" },
+]
+
[[package]]
name = "fastapi"
version = "0.135.1"
@@ -2818,6 +2827,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/cb/29/518f32faf6edad9f56d6e0107217f7de6b79f297a47170414a2bd4be7f01/pytest_snapshot-0.9.0-py3-none-any.whl", hash = "sha256:4b9fe1c21c868fe53a545e4e3184d36bc1c88946e3f5c1d9dd676962a9b3d4ab", size = 10715, upload-time = "2022-04-23T17:35:30.288Z" },
]
+[[package]]
+name = "pytest-xdist"
+version = "3.8.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "execnet" },
+ { name = "pytest" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/78/b4/439b179d1ff526791eb921115fca8e44e596a13efeda518b9d845a619450/pytest_xdist-3.8.0.tar.gz", hash = "sha256:7e578125ec9bc6050861aa93f2d59f1d8d085595d6551c2c90b6f4fad8d3a9f1", size = 88069, upload-time = "2025-07-01T13:30:59.346Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ca/31/d4e37e9e550c2b92a9cbc2e4d0b7420a27224968580b5a447f420847c975/pytest_xdist-3.8.0-py3-none-any.whl", hash = "sha256:202ca578cfeb7370784a8c33d6d05bc6e13b4f25b5053c30a152269fd10f0b88", size = 46396, upload-time = "2025-07-01T13:30:56.632Z" },
+]
+
[[package]]
name = "python-dateutil"
version = "2.9.0.post0"
@@ -3116,6 +3138,7 @@ dev = [
{ name = "pytest" },
{ name = "pytest-asyncio" },
{ name = "pytest-snapshot" },
+ { name = "pytest-xdist" },
{ name = "respx" },
{ name = "ruff" },
{ name = "time-machine" },
@@ -3136,6 +3159,7 @@ dev = [
{ name = "pytest" },
{ name = "pytest-asyncio" },
{ name = "pytest-snapshot" },
+ { name = "pytest-xdist" },
{ name = "respx" },
{ name = "ruff" },
{ name = "time-machine" },
@@ -3170,6 +3194,7 @@ requires-dist = [
{ name = "pytest", marker = "extra == 'dev'", specifier = ">=8,<9" },
{ name = "pytest-asyncio", marker = "extra == 'dev'", specifier = ">=0.23,<1" },
{ name = "pytest-snapshot", marker = "extra == 'dev'", specifier = ">=0.9,<1" },
+ { name = "pytest-xdist", marker = "extra == 'dev'", specifier = ">=3.5,<4" },
{ name = "pyyaml", specifier = ">=6.0,<7" },
{ name = "respx", marker = "extra == 'dev'", specifier = ">=0.21,<1" },
{ name = "rich", specifier = ">=13,<14" },
@@ -3219,6 +3244,7 @@ dev = [
{ name = "pytest", specifier = ">=8,<9" },
{ name = "pytest-asyncio", specifier = ">=0.23,<1" },
{ name = "pytest-snapshot", specifier = ">=0.9,<1" },
+ { name = "pytest-xdist", specifier = ">=3.5,<4" },
{ name = "respx", specifier = ">=0.21,<1" },
{ name = "ruff", specifier = ">=0.6,<1" },
{ name = "time-machine", specifier = ">=2.14,<3" },