Skip to content

Commit c3e4094

Browse files
committed
Add parallel testing demo
1 parent 559ffe2 commit c3e4094

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

.github/workflows/parallel_dir.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ jobs:
3939
run: |
4040
from os import environ
4141
from pathlib import Path
42-
test_dirs = set()
42+
43+
# Deduplicate directory paths.
4344
with open("collected.txt", encoding="utf-8") as lines:
44-
for line in lines:
45-
parts = line.strip().partition("::")
46-
test_dirs.add(str(Path(parts[0]).parent))
47-
test_dirs = sorted(list(test_dirs))
45+
test_dirs = sorted({str(Path(line.partition("::")[0]).parent) for line in lines})
46+
4847
print(f"::notice ::Directories: {test_dirs}")
4948
with open(environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
5049
print(f"TEST_DIRS={test_dirs}", file=f)

.github/workflows/parallel_file.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ jobs:
3939
run: |
4040
from os import environ
4141
42-
# Deduplicate file paths. The same file will show up
43-
# multiple times because each file can have many tests.
42+
# Deduplicate file paths.
4443
with open("collected.txt", encoding="utf-8") as lines:
45-
paths = sorted({line.strip().partition("::")[0] for line in lines})
44+
paths = sorted({line.partition("::")[0] for line in lines})
4645
47-
max_size = 3
46+
max_size = 3 # Max files per group
4847
test_groups = {"include": []}
4948
50-
# Slice the list of paths into subgroups.
49+
# Slice the list of paths into sublists and quote each path.
5150
for i, j in enumerate(range(0, len(paths), max_size), start=1):
52-
test_groups["include"].append({"name": f"Group {i}", "files": " ".join(paths[j : j + max_size])})
51+
quoted = [f"'{path}'" for path in paths[j : j + max_size]]
52+
test_groups["include"].append({"name": f"Group {i}", "paths": " ".join(quoted)})
5353
5454
print(f"::notice ::Groups: {test_groups}")
5555
with open(environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f:
@@ -77,4 +77,6 @@ jobs:
7777
uv tree
7878
7979
- name: Run test
80-
run: uv run -- pytest '${{ matrix.files }}'
80+
# Don't quote the matrix argument because it would cause pytest
81+
# to treat the entire list of file paths as a single argument.
82+
run: uv run -- pytest ${{ matrix.paths }}

0 commit comments

Comments
 (0)