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

Method run

Lib/unittest/runner.py:241–313  ·  view source on GitHub ↗

Run the given test case or test suite.

(self, test)

Source from the content-addressed store, hash-verified

239 self.stream.writeln("")
240
241 def run(self, test):
242 "Run the given test case or test suite."
243 result = self._makeResult()
244 registerResult(result)
245 result.failfast = self.failfast
246 result.buffer = self.buffer
247 result.tb_locals = self.tb_locals
248 with warnings.catch_warnings():
249 if self.warnings:
250 # if self.warnings is set, use it to filter all the warnings
251 warnings.simplefilter(self.warnings)
252 start_time = time.perf_counter()
253 startTestRun = getattr(result, 'startTestRun', None)
254 if startTestRun is not None:
255 startTestRun()
256 try:
257 test(result)
258 finally:
259 stopTestRun = getattr(result, 'stopTestRun', None)
260 if stopTestRun is not None:
261 stopTestRun()
262 stop_time = time.perf_counter()
263 time_taken = stop_time - start_time
264 result.printErrors()
265 if self.durations is not None:
266 self._printDurations(result)
267
268 if hasattr(result, 'separator2'):
269 self.stream.writeln(result.separator2)
270
271 run = result.testsRun
272 self.stream.writeln("Ran %d test%s in %.3fs" %
273 (run, run != 1 and "s" or "", time_taken))
274 self.stream.writeln()
275
276 expected_fails = unexpected_successes = skipped = 0
277 try:
278 results = map(len, (result.expectedFailures,
279 result.unexpectedSuccesses,
280 result.skipped))
281 except AttributeError:
282 pass
283 else:
284 expected_fails, unexpected_successes, skipped = results
285
286 infos = []
287 t = get_theme(tty_file=self.stream).unittest
288
289 if not result.wasSuccessful():
290 self.stream.write(f"{t.fail_info}FAILED{t.reset}")
291 failed, errored = len(result.failures), len(result.errors)
292 if failed:
293 infos.append(f"{t.fail_info}failures={failed}{t.reset}")
294 if errored:
295 infos.append(f"{t.fail_info}errors={errored}{t.reset}")
296 elif run == 0 and not skipped:
297 self.stream.write(f"{t.warn}NO TESTS RAN{t.reset}")
298 else:

Callers 8

testRunnerMethod · 0.95
testBufferAndFailfastMethod · 0.95
test_localsMethod · 0.95
runMethod · 0.95
_testMethod · 0.95

Calls 12

_makeResultMethod · 0.95
_printDurationsMethod · 0.95
get_themeFunction · 0.90
registerResultFunction · 0.85
testFunction · 0.50
printErrorsMethod · 0.45
writelnMethod · 0.45
wasSuccessfulMethod · 0.45
writeMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
flushMethod · 0.45

Tested by 8

testRunnerMethod · 0.76
testBufferAndFailfastMethod · 0.76
test_localsMethod · 0.76
runMethod · 0.76
_testMethod · 0.76