Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

perf(core): parallelize unit tests with pytest-xdist (#213)

Rufus8b9a82289ccb
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b02610fa..1a562865 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -56,8 +56,11 @@ jobs:
- name: Install dependencies
run: cd packages/core && uv sync --extra dev
+ # pytest-xdist: one worker per core (4 on ubuntu-latest). `loadfile` keeps
+ # each test module on a single worker, so module-level state behaves as in
+ # a serial run.
- name: Run unit tests
- run: cd packages/core && uv run pytest tests/unit/ -v --tb=short
+ run: cd packages/core && uv run pytest tests/unit/ -n auto --dist loadfile --tb=short
ui-typecheck:
name: UI type check
diff --git a/packages/core/pyproject.toml b/packages/core/pyproject.toml
index 160157dd..c610d86e 100644
--- a/packages/core/pyproject.toml
+++ b/packages/core/pyproject.toml
@@ -47,6 +47,7 @@ Issues = "https://github.com/SenteLabsAI/OpenExecutive/issues"
dev = [
"pytest>=8.2.0",
"pytest-asyncio>=0.23.0",
+ "pytest-xdist>=3.6.0",
"ruff>=0.4.0",
"mypy>=1.10.0",
"types-pyyaml>=6.0.12",
@@ -99,5 +100,6 @@ dev = [
"mypy>=2.1.0",
"pytest>=9.0.3",
"pytest-asyncio>=0.23.0",
+ "pytest-xdist>=3.6.0",
"ruff>=0.15.13",
]
diff --git a/packages/core/tests/unit/test_target_validation.py b/packages/core/tests/unit/test_target_validation.py
index ca929032..832fa2a5 100644
--- a/packages/core/tests/unit/test_target_validation.py
+++ b/packages/core/tests/unit/test_target_validation.py
@@ -134,7 +134,7 @@ async def test_empty_body_is_not_feed_no_crash(
@pytest.mark.asyncio
@pytest.mark.asyncio
async def test_readability_check_is_bounded(monkeypatch: pytest.MonkeyPatch) -> None:
- """Only the head of a huge body is reduced for the readability check."""
+ """Only the head of a body over the cap is reduced for the readability check."""
calls: list[int] = []
def fake_html_to_text(body: bytes) -> str:
@@ -142,7 +142,7 @@ async def test_readability_check_is_bounded(monkeypatch: pytest.MonkeyPatch) ->
return "x" * 500
monkeypatch.setattr(tv, "html_to_text", fake_html_to_text)
- _install(monkeypatch, fetch=_fetch_returning(b"<p>" * 1_000_000))
+ _install(monkeypatch, fetch=_fetch_returning(b"<p>" * (tv._READABILITY_SCAN_BYTES // 3 + 1)))
st, _target, _config = await tv.validate_and_normalize_target("rss", "https://big.example/x", {})
assert st == "page_watch"
assert calls == [tv._READABILITY_SCAN_BYTES]
diff --git a/packages/core/uv.lock b/packages/core/uv.lock
index 24140cf4..b13765f8 100644
--- a/packages/core/uv.lock
+++ b/packages/core/uv.lock
@@ -743,6 +743,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/c1/8b/5fe2cc11fee489817272089c4203e679c63b570a5aaeb18d852ae3cbba6a/et_xmlfile-2.0.0-py3-none-any.whl", hash = "sha256:7a91720bc756843502c3b7504c77b8fe44217c85c537d85037f0f536151b2caa", size = 18059, upload-time = "2024-10-25T17:25:39.051Z" },
]
+[[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.136.1"
@@ -2133,6 +2142,7 @@ dev = [
{ name = "mypy" },
{ name = "pytest" },
{ name = "pytest-asyncio" },
+ { name = "pytest-xdist" },
{ name = "ruff" },
{ name = "types-aiofiles" },
{ name = "types-pyyaml" },
@@ -2143,6 +2153,7 @@ dev = [
{ name = "mypy" },
{ name = "pytest" },
{ name = "pytest-asyncio" },
+ { name = "pytest-xdist" },
{ name = "ruff" },
]
@@ -2169,6 +2180,7 @@ requires-dist = [
{ name = "pypdf", specifier = ">=4.2.0" },
{ name = "pytest", marker = "extra == 'dev'", specifier = ">=8.2.0" },
{ name = "pytest-asyncio", marker = "extra == 'dev'", specifier = ">=0.23.0" },
+ { name = "pytest-xdist", marker = "extra == 'dev'", specifier = ">=3.6.0" },
{ name = "python-docx", specifier = ">=1.1.0" },
{ name = "python-multipart", specifier = ">=0.0.9" },
{ name = "pyyaml", specifier = ">=6.0.1" },
@@ -2189,6 +2201,7 @@ dev = [
{ name = "mypy", specifier = ">=2.1.0" },
{ name = "pytest", specifier = ">=9.0.3" },
{ name = "pytest-asyncio", specifier = ">=0.23.0" },
+ { name = "pytest-xdist", specifier = ">=3.6.0" },
{ name = "ruff", specifier = ">=0.15.13" },
]
@@ -2925,6 +2938,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/e5/35/f8b19922b6a25bc0880171a2f1a003eaeb93657475193ab516fd87cac9da/pytest_asyncio-1.3.0-py3-none-any.whl", hash = "sha256:611e26147c7f77640e6d0a92a38ed17c3e9848063698d5c93d5aa7aa11cebff5", size = 15075, upload-time = "2025-11-10T16:07:45.537Z" },
]
+[[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"