|
10 | 10 | import tempfile |
11 | 11 | import unittest |
12 | 12 | from collections import defaultdict |
| 13 | +from concurrent.futures import ProcessPoolExecutor, as_completed |
13 | 14 | from pathlib import Path |
14 | 15 | from typing import TYPE_CHECKING, Callable, Optional |
15 | 16 |
|
@@ -438,17 +439,28 @@ def process_test_files( |
438 | 439 |
|
439 | 440 | function_to_test_map = defaultdict(set) |
440 | 441 |
|
441 | | - with test_files_progress_bar(total=len(file_to_test_map), description="Processing test files") as ( |
442 | | - progress, |
443 | | - task_id, |
| 442 | + with ( |
| 443 | + ProcessPoolExecutor() as executor, |
| 444 | + test_files_progress_bar(total=len(file_to_test_map), description="Processing test files") as ( |
| 445 | + progress, |
| 446 | + task_id, |
| 447 | + ), |
444 | 448 | ): |
| 449 | + futures_map = {} |
445 | 450 | for test_file, functions in file_to_test_map.items(): |
446 | | - _, local_results = _process_single_test_file(test_file, functions, project_root_path, test_framework) |
447 | | - |
448 | | - for qualified_name, function_called_in_test in local_results: |
449 | | - function_to_test_map[qualified_name].add(function_called_in_test) |
450 | | - |
451 | | - progress.advance(task_id) |
| 451 | + future = executor.submit(_process_single_test_file, test_file, functions, project_root_path, test_framework) |
| 452 | + futures_map[future] = test_file |
| 453 | + |
| 454 | + for future in as_completed(futures_map): |
| 455 | + original_test_file = futures_map[future] |
| 456 | + try: |
| 457 | + _, local_results = future.result() |
| 458 | + for qualified_name, function_called_in_test in local_results: |
| 459 | + function_to_test_map[qualified_name].add(function_called_in_test) |
| 460 | + except Exception as e: |
| 461 | + logger.error(f"Error processing test file {original_test_file}: {e}") |
| 462 | + finally: |
| 463 | + progress.advance(task_id) |
452 | 464 |
|
453 | 465 | function_to_tests_dict = {function: list(tests) for function, tests in function_to_test_map.items()} |
454 | 466 | num_discovered_tests = sum(len(tests) for tests in function_to_tests_dict.values()) |
|
0 commit comments