MCPcopy Index your code
hub / github.com/python/cpython / _parallelize_tests

Function _parallelize_tests

Lib/test/libregrtest/single.py:56–76  ·  view source on GitHub ↗
(suite, parallel_threads: int)

Source from the content-addressed store, hash-verified

54 suite._tests = newtests
55
56def _parallelize_tests(suite, parallel_threads: int):
57 def is_thread_unsafe(test):
58 test_method = getattr(test, test._testMethodName)
59 instance = test_method.__self__
60 return (getattr(test_method, "__unittest_thread_unsafe__", False) or
61 getattr(instance, "__unittest_thread_unsafe__", False))
62
63 newtests: list[object] = []
64 for test in suite._tests:
65 if isinstance(test, unittest.TestSuite):
66 _parallelize_tests(test, parallel_threads)
67 newtests.append(test)
68 continue
69
70 if is_thread_unsafe(test):
71 # Don't parallelize thread-unsafe tests
72 newtests.append(test)
73 continue
74
75 newtests.append(ParallelTestCase(test, parallel_threads))
76 suite._tests = newtests
77
78def _run_suite(suite):
79 """Run tests from a unittest.TestSuite-derived class."""

Callers 1

run_unittestFunction · 0.85

Calls 3

is_thread_unsafeFunction · 0.85
ParallelTestCaseClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…