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

Method run

Lib/test/libregrtest/parallel_case.py:25–78  ·  view source on GitHub ↗
(self, result=None)

Source from the content-addressed store, hash-verified

23 test_case.run(result)
24
25 def run(self, result=None):
26 if result is None:
27 result = test_case.defaultTestResult()
28 startTestRun = getattr(result, 'startTestRun', None)
29 stopTestRun = getattr(result, 'stopTestRun', None)
30 if startTestRun is not None:
31 startTestRun()
32 else:
33 stopTestRun = None
34
35 # Called at the beginning of each test. See TestCase.run.
36 result.startTest(self)
37
38 cases = [copy.copy(self.test_case) for _ in range(self.num_threads)]
39 results = [unittest.TestResult() for _ in range(self.num_threads)]
40
41 barrier = threading.Barrier(self.num_threads)
42 threads = []
43 for i, (case, r) in enumerate(zip(cases, results)):
44 thread = threading.Thread(target=self.run_worker,
45 args=(case, r, barrier),
46 name=f"{str(self.test_case)}-{i}",
47 daemon=True)
48 threads.append(thread)
49
50 for thread in threads:
51 thread.start()
52
53 for threads in threads:
54 threads.join()
55
56 # Aggregate test results
57 if all(r.wasSuccessful() for r in results):
58 result.addSuccess(self)
59
60 # Note: We can't call result.addError, result.addFailure, etc. because
61 # we no longer have the original exception, just the string format.
62 for r in results:
63 if len(r.errors) > 0 or len(r.failures) > 0:
64 result._mirrorOutput = True
65 result.errors.extend(r.errors)
66 result.failures.extend(r.failures)
67 result.skipped.extend(r.skipped)
68 result.expectedFailures.extend(r.expectedFailures)
69 result.unexpectedSuccesses.extend(r.unexpectedSuccesses)
70 result.collectedDurations.extend(r.collectedDurations)
71
72 if any(r.shouldStop for r in results):
73 result.stop()
74
75 # Test has finished running
76 result.stopTest(self)
77 if stopTestRun is not None:
78 stopTestRun()

Callers 1

run_workerMethod · 0.45

Calls 15

startMethod · 0.95
enumerateFunction · 0.85
strFunction · 0.85
BarrierMethod · 0.80
anyFunction · 0.50
defaultTestResultMethod · 0.45
startTestMethod · 0.45
copyMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
wasSuccessfulMethod · 0.45
addSuccessMethod · 0.45

Tested by

no test coverage detected