Skip to content

Commit 7f5507b

Browse files
committed
Speed up mypy regr test in CI
1 parent 76b1f83 commit 7f5507b

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
with:
7979
version-file: "requirements-tests.txt"
8080
- run: uv pip install -r requirements-tests.txt --system
81-
- run: python ./tests/regr_test.py --all --verbosity QUIET
81+
- run: python ./tests/regr_test.py --all --verbosity QUIET --max-workers=8
8282

8383
pyright:
8484
name: "pyright: Run test cases"

tests/regr_test.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ class Verbosity(IntEnum):
107107
"Note that this cannot be specified if --all is also specified."
108108
),
109109
)
110+
parser.add_argument(
111+
"-j",
112+
"--max-workers",
113+
type=int,
114+
default=os.cpu_count(),
115+
help="Maximum number of packages or mypy subprocesses to run concurrently",
116+
)
110117

111118
_PRINT_QUEUE: queue.SimpleQueue[str] = queue.SimpleQueue()
112119

@@ -298,6 +305,7 @@ def concurrently_run_testcases(
298305
verbosity: Verbosity,
299306
platforms_to_test: list[str],
300307
versions_to_test: list[str],
308+
max_workers: int | None,
301309
) -> list[Result]:
302310
packageinfo_to_tempdir = {
303311
distribution_info: Path(stack.enter_context(tempfile.TemporaryDirectory())) for distribution_info in testcase_directories
@@ -348,7 +356,7 @@ def cleanup_threads(
348356
printer_thread = threading.Thread(target=print_queued_messages, args=(event,))
349357
printer_thread.start()
350358

351-
with concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
359+
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
352360
# Each temporary directory may be used by multiple processes concurrently during the next step;
353361
# must make sure that they're all setup correctly before starting the next step,
354362
# in order to avoid race conditions
@@ -358,7 +366,8 @@ def cleanup_threads(
358366
]
359367

360368
with cleanup_threads(event, printer_thread, executor):
361-
concurrent.futures.wait(testcase_futures)
369+
for future in concurrent.futures.as_completed(testcase_futures):
370+
future.result()
362371

363372
mypy_futures = [executor.submit(task) for task in to_do]
364373

@@ -372,6 +381,8 @@ def cleanup_threads(
372381

373382
def main() -> ReturnCode:
374383
args = parser.parse_args()
384+
if args.max_workers is not None and args.max_workers < 1:
385+
parser.error("--max-workers must be a positive integer")
375386

376387
testcase_directories = args.packages_to_test or get_all_testcase_directories()
377388
verbosity = Verbosity[args.verbosity]
@@ -388,7 +399,9 @@ def main() -> ReturnCode:
388399
results: list[Result] | None = None
389400

390401
with ExitStack() as stack:
391-
results = concurrently_run_testcases(stack, testcase_directories, verbosity, platforms_to_test, versions_to_test)
402+
results = concurrently_run_testcases(
403+
stack, testcase_directories, verbosity, platforms_to_test, versions_to_test, args.max_workers
404+
)
392405

393406
assert results is not None
394407
if not results:

0 commit comments

Comments
 (0)