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

Class DocTestRunner

Lib/doctest.py:1203–1705  ·  view source on GitHub ↗

A class used to run DocTest test cases, and accumulate statistics. The `run` method is used to process a single DocTest case. It returns a TestResults instance. >>> save_colorize = _colorize.COLORIZE >>> _colorize.COLORIZE = False >>> tests = DocTestFinder().f

Source from the content-addressed store, hash-verified

1201######################################################################
1202
1203class DocTestRunner:
1204 """
1205 A class used to run DocTest test cases, and accumulate statistics.
1206 The `run` method is used to process a single DocTest case. It
1207 returns a TestResults instance.
1208
1209 >>> save_colorize = _colorize.COLORIZE
1210 >>> _colorize.COLORIZE = False
1211
1212 >>> tests = DocTestFinder().find(_TestClass)
1213 >>> runner = DocTestRunner(verbose=False)
1214 >>> tests.sort(key = lambda test: test.name)
1215 >>> for test in tests:
1216 ... print(test.name, '->', runner.run(test))
1217 _TestClass -> TestResults(failed=0, attempted=2)
1218 _TestClass.__init__ -> TestResults(failed=0, attempted=2)
1219 _TestClass.get -> TestResults(failed=0, attempted=2)
1220 _TestClass.square -> TestResults(failed=0, attempted=1)
1221
1222 The `summarize` method prints a summary of all the test cases that
1223 have been run by the runner, and returns an aggregated TestResults
1224 instance:
1225
1226 >>> runner.summarize(verbose=1)
1227 4 items passed all tests:
1228 2 tests in _TestClass
1229 2 tests in _TestClass.__init__
1230 2 tests in _TestClass.get
1231 1 test in _TestClass.square
1232 7 tests in 4 items.
1233 7 passed.
1234 Test passed.
1235 TestResults(failed=0, attempted=7)
1236
1237 The aggregated number of tried examples and failed examples is also
1238 available via the `tries`, `failures` and `skips` attributes:
1239
1240 >>> runner.tries
1241 7
1242 >>> runner.failures
1243 0
1244 >>> runner.skips
1245 0
1246
1247 The comparison between expected outputs and actual outputs is done
1248 by an `OutputChecker`. This comparison may be customized with a
1249 number of option flags; see the documentation for `testmod` for
1250 more information. If the option flags are insufficient, then the
1251 comparison may also be customized by passing a subclass of
1252 `OutputChecker` to the constructor.
1253
1254 The test runner's display output can be controlled in two ways.
1255 First, an output function (`out`) can be passed to
1256 `TestRunner.run`; this function will be called with strings that
1257 should be displayed. It defaults to `sys.stdout.write`. If
1258 capturing the output is not sufficient, then the display output
1259 can be also customized by subclassing DocTestRunner, and
1260 overriding the methods `report_start`, `report_success`,

Callers 3

testmodFunction · 0.85
testfileFunction · 0.85
run_docstring_examplesFunction · 0.85

Calls 1

compileMethod · 0.45

Tested by 3

testmodFunction · 0.68
testfileFunction · 0.68
run_docstring_examplesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…