MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / DocTestCase

Class DocTestCase

tools/python-3.11.9-amd64/Lib/doctest.py:2192–2353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2190
2191
2192class DocTestCase(unittest.TestCase):
2193
2194 def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
2195 checker=None):
2196
2197 unittest.TestCase.__init__(self)
2198 self._dt_optionflags = optionflags
2199 self._dt_checker = checker
2200 self._dt_test = test
2201 self._dt_setUp = setUp
2202 self._dt_tearDown = tearDown
2203
2204 def setUp(self):
2205 test = self._dt_test
2206 self._dt_globs = test.globs.copy()
2207
2208 if self._dt_setUp is not None:
2209 self._dt_setUp(test)
2210
2211 def tearDown(self):
2212 test = self._dt_test
2213
2214 if self._dt_tearDown is not None:
2215 self._dt_tearDown(test)
2216
2217 # restore the original globs
2218 test.globs.clear()
2219 test.globs.update(self._dt_globs)
2220
2221 def runTest(self):
2222 test = self._dt_test
2223 old = sys.stdout
2224 new = StringIO()
2225 optionflags = self._dt_optionflags
2226
2227 if not (optionflags & REPORTING_FLAGS):
2228 # The option flags don't include any reporting flags,
2229 # so add the default reporting flags
2230 optionflags |= _unittest_reportflags
2231
2232 runner = DocTestRunner(optionflags=optionflags,
2233 checker=self._dt_checker, verbose=False)
2234
2235 try:
2236 runner.DIVIDER = "-"*70
2237 failures, tries = runner.run(
2238 test, out=new.write, clear_globs=False)
2239 finally:
2240 sys.stdout = old
2241
2242 if failures:
2243 raise self.failureException(self.format_failure(new.getvalue()))
2244
2245 def format_failure(self, err):
2246 test = self._dt_test
2247 if test.lineno is None:
2248 lineno = 'unknown line number'
2249 else:

Callers 1

DocTestSuiteFunction · 0.85

Calls

no outgoing calls

Tested by 1

DocTestSuiteFunction · 0.68