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

Class DocTestCase

Lib/doctest.py:2358–2518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2356
2357
2358class DocTestCase(unittest.TestCase):
2359
2360 def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
2361 checker=None):
2362
2363 super().__init__()
2364 self._dt_optionflags = optionflags
2365 self._dt_checker = checker
2366 self._dt_test = test
2367 self._dt_setUp = setUp
2368 self._dt_tearDown = tearDown
2369
2370 def setUp(self):
2371 test = self._dt_test
2372 self._dt_globs = test.globs.copy()
2373
2374 if self._dt_setUp is not None:
2375 self._dt_setUp(test)
2376
2377 def tearDown(self):
2378 test = self._dt_test
2379
2380 if self._dt_tearDown is not None:
2381 self._dt_tearDown(test)
2382
2383 # restore the original globs
2384 test.globs.clear()
2385 test.globs.update(self._dt_globs)
2386
2387 def run(self, result=None):
2388 self._test_result = result
2389 return super().run(result)
2390
2391 def runTest(self):
2392 test = self._dt_test
2393 optionflags = self._dt_optionflags
2394 result = self._test_result
2395
2396 if not (optionflags & REPORTING_FLAGS):
2397 # The option flags don't include any reporting flags,
2398 # so add the default reporting flags
2399 optionflags |= _unittest_reportflags
2400 if getattr(result, 'failfast', False):
2401 optionflags |= FAIL_FAST
2402
2403 runner = _DocTestCaseRunner(optionflags=optionflags,
2404 checker=self._dt_checker, verbose=False,
2405 test_case=self, test_result=result)
2406 results = runner.run(test, clear_globs=False)
2407 if results.skipped == results.attempted:
2408 raise unittest.SkipTest("all examples were skipped")
2409
2410 def format_failure(self, err):
2411 test = self._dt_test
2412 if test.lineno is None:
2413 lineno = 'unknown line number'
2414 else:
2415 lineno = '%s' % test.lineno

Callers 1

DocTestSuiteFunction · 0.85

Calls

no outgoing calls

Tested by 1

DocTestSuiteFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…