MCPcopy Index your code
hub / github.com/RustPython/RustPython / DocTestRunner

Class DocTestRunner

Lib/doctest.py:1183–1678  ·  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

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

Callers 4

testmodFunction · 0.85
testfileFunction · 0.85
run_docstring_examplesFunction · 0.85
runTestMethod · 0.85

Calls 1

compileMethod · 0.45

Tested by 4

testmodFunction · 0.68
testfileFunction · 0.68
run_docstring_examplesFunction · 0.68
runTestMethod · 0.68