(args, modules, options)
| 392 | |
| 393 | |
| 394 | def load_test_suite(args, modules, options): |
| 395 | loader = unittest.TestLoader() |
| 396 | error_on_legacy_suite_names(args) |
| 397 | unmatched_test_names = set(args) |
| 398 | using_parallel_suite = None |
| 399 | |
| 400 | tests = [] |
| 401 | for m in modules: |
| 402 | names_in_module = [] |
| 403 | for name in list(unmatched_test_names): |
| 404 | try: |
| 405 | operator.attrgetter(name)(m) |
| 406 | names_in_module.append(name) |
| 407 | unmatched_test_names.remove(name) |
| 408 | except AttributeError: |
| 409 | pass |
| 410 | if names_in_module: |
| 411 | # Ensure verbose output for the benchmark suite, as otherwise no benchmark |
| 412 | # results are emitted. |
| 413 | if m.__name__ == 'test_benchmark': |
| 414 | options.verbose = max(options.verbose, 1) |
| 415 | |
| 416 | loaded_tests = loader.loadTestsFromNames(sorted(names_in_module), m) |
| 417 | tests += flattened_tests(loaded_tests) |
| 418 | is_parallel_module = use_parallel_suite(m) |
| 419 | if using_parallel_suite is None: |
| 420 | using_parallel_suite = is_parallel_module |
| 421 | else: |
| 422 | # All the following modules must match in their support for the parallel runner. |
| 423 | if is_parallel_module != using_parallel_suite: |
| 424 | utils.exit_with_error(f'attempt to mix parallel and non-parallel test modules ({m.__name__})') |
| 425 | |
| 426 | # If we are only running a single tests, never use the parallel tests suite. |
| 427 | # This means that the output of a single test is always going to be in `out/test/` rather |
| 428 | # than a random temporary directory. |
| 429 | if len(tests) == 1 and not options.repeat > 1: |
| 430 | using_parallel_suite = False |
| 431 | suite = create_test_suite(using_parallel_suite, options) |
| 432 | |
| 433 | if options.failing_and_slow_first: |
| 434 | tests = sorted(tests, key=cmp_to_key(create_test_run_sorter(options.max_failures < len(tests) / 2))) |
| 435 | |
| 436 | found_start = not options.start_at |
| 437 | total_tests = 0 |
| 438 | for test in tests: |
| 439 | if not found_start: |
| 440 | # Skip over tests until we find the start |
| 441 | if test.id().endswith(options.start_at): |
| 442 | found_start = True |
| 443 | else: |
| 444 | continue |
| 445 | for _x in range(options.repeat): |
| 446 | total_tests += 1 |
| 447 | suite.addTest(test) |
| 448 | |
| 449 | if not found_start: |
| 450 | utils.exit_with_error(f'unable to find --start-at test: {options.start_at}') |
| 451 | return suite, unmatched_test_names |
no test coverage detected