Skip to content

Commit a4e5314

Browse files
committed
test(pytest): add parallel execution support and fix zipapp tests
- Add pytest-xdist dependency for parallel test execution - Add parallel test tasks (test:parallel, test:fast, etc.) - Update check and check:fix tasks to use parallel execution - Split zipapp tests into separate files with __runtime_mode__ marker - Remove skip decorators - conftest now filters zipapp tests automatically - Add comment in pytest.ini explaining parallel execution is opt-in
1 parent 55dc4db commit a4e5314

File tree

7 files changed

+645
-445
lines changed

7 files changed

+645
-445
lines changed

poetry.lock

Lines changed: 182 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ Changelog = "https://github.com/apathetic-tools/python-utils/releases"
3737
# --- Development tasks ---
3838
[tool.poe.tasks]
3939
# 🧩 All-in-one
40-
"check:fix" = ["pre-commit:install", "fix", "typecheck", "test"]
40+
"check:fix" = ["pre-commit:install", "fix", "typecheck", "test:parallel"]
4141

4242
# 🔍 Linting and static checks
43-
check = ["lint", "typecheck", "test"]
43+
check = ["lint", "typecheck", "test:parallel"]
4444
lint = ["lint:ruff"]
4545
"lint:ruff" = "ruff check ."
4646

@@ -53,14 +53,48 @@ typecheck = ["typecheck:mypy", "typecheck:pyright"]
5353
# 🧪 Tests (runs all three: installed + singlefile + zipapp)
5454
test = ["test:pytest:installed", "test:pytest:script", "test:pytest:zipapp"]
5555
"test:pytest:installed" = "pytest"
56+
"test:pytest:installed:parallel" = "pytest -n auto"
5657
"test:pytest:script" = [
5758
"build:script",
5859
{ cmd = "pytest", env = { RUNTIME_MODE="singlefile" } }
5960
]
61+
"test:pytest:script:parallel" = [
62+
"build:script",
63+
{ cmd = "pytest -n auto", env = { RUNTIME_MODE="singlefile" } }
64+
]
6065
"test:pytest:zipapp" = [
6166
"build:zipapp",
6267
{ cmd = "pytest", env = { RUNTIME_MODE="zipapp" } }
6368
]
69+
"test:pytest:zipapp:parallel" = [
70+
"build:zipapp",
71+
{ cmd = "pytest -n auto", env = { RUNTIME_MODE="zipapp" } }
72+
]
73+
74+
# 🚀 Fast test runs (for development)
75+
# Fast: installed mode only, parallel, skip slow tests
76+
"test:fast" = "pytest -n auto -m 'not slow'"
77+
# Fast: all three modes, parallel, skip slow tests
78+
"test:fast:installed" = "pytest -n auto -m 'not slow'"
79+
"test:fast:script" = [
80+
"build:script",
81+
{ cmd = "pytest -n auto -m 'not slow'", env = { RUNTIME_MODE="singlefile" } }
82+
]
83+
"test:fast:zipapp" = [
84+
"build:zipapp",
85+
{ cmd = "pytest -n auto -m 'not slow'", env = { RUNTIME_MODE="zipapp" } }
86+
]
87+
"test:fast:all" = [
88+
"test:fast:installed",
89+
"test:fast:script",
90+
"test:fast:zipapp"
91+
]
92+
# Parallel: all three modes with parallel execution
93+
"test:parallel" = [
94+
"test:pytest:installed:parallel",
95+
"test:pytest:script:parallel",
96+
"test:pytest:zipapp:parallel"
97+
]
6498

6599
# 📊 Coverage reporting
66100
"coverage:clean" = { shell = "rm -f .coverage .coverage.*" }
@@ -116,17 +150,17 @@ fix = ["sync:ai:guidance", "fix:ruff:installed", "fix:format:installed"]
116150
"env:py3x" = "bash dev/env_use_py3x.sh"
117151
"test:py310" = [
118152
"env:py310",
119-
"test",
153+
"test:parallel",
120154
"env:py3x"
121155
]
122156
"test:py311" = [
123157
"env:py311",
124-
"test",
158+
"test:parallel",
125159
"env:py3x"
126160
]
127161
"test:py312" = [
128162
"env:py312",
129-
"test",
163+
"test:parallel",
130164
"env:py3x"
131165
]
132166

@@ -154,6 +188,7 @@ dev = [
154188
"pytest-timeout (>=2.4.0,<3.0.0)",
155189
"pytest-benchmark (>=5.1.0,<6.0.0)",
156190
"pytest-cov (>=7.0.0,<8.0.0)",
191+
"pytest-xdist",
157192
"pyright (>=1.1.407,<2.0.0)",
158193
"shiv (>=1.0.0,<2.0.0)",
159194
"python-semantic-release (>=10.0.0,<11.0.0)",

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ pythonpath = src
3333

3434
# Show more context in assertion diffs (-s needed for early prints)
3535
# Exclude pocket-build compatibility tests (to be migrated in Phase 5+6)
36+
# Parallel execution: use -n auto to auto-detect CPU count, or -n N for N workers
37+
# Note: parallel execution is opt-in via command line (not in addopts) to avoid
38+
# issues with test isolation and shared resources
3639
addopts = -ra -q --color=yes --show-capture=all --tb=short

0 commit comments

Comments
 (0)