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

Function DocTestSuite

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

Convert doctest tests for a module to a unittest test suite. This converts each documentation string in a module that contains doctest tests to a unittest test case. If any of the tests in a doc string fail, then the test case fails. An exception is raised showing the n

(module=None, globs=None, extraglobs=None, test_finder=None,
                 **options)

Source from the content-addressed store, hash-verified

2376
2377
2378def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
2379 **options):
2380 """
2381 Convert doctest tests for a module to a unittest test suite.
2382
2383 This converts each documentation string in a module that
2384 contains doctest tests to a unittest test case. If any of the
2385 tests in a doc string fail, then the test case fails. An exception
2386 is raised showing the name of the file containing the test and a
2387 (sometimes approximate) line number.
2388
2389 The `module` argument provides the module to be tested. The argument
2390 can be either a module or a module name.
2391
2392 If no argument is given, the calling module is used.
2393
2394 A number of options may be provided as keyword arguments:
2395
2396 setUp
2397 A set-up function. This is called before running the
2398 tests in each file. The setUp function will be passed a DocTest
2399 object. The setUp function can access the test globals as the
2400 globs attribute of the test passed.
2401
2402 tearDown
2403 A tear-down function. This is called after running the
2404 tests in each file. The tearDown function will be passed a DocTest
2405 object. The tearDown function can access the test globals as the
2406 globs attribute of the test passed.
2407
2408 globs
2409 A dictionary containing initial global variables for the tests.
2410
2411 optionflags
2412 A set of doctest option flags expressed as an integer.
2413 """
2414
2415 if test_finder is None:
2416 test_finder = DocTestFinder()
2417
2418 module = _normalize_module(module)
2419 tests = test_finder.find(module, globs=globs, extraglobs=extraglobs)
2420
2421 if not tests and sys.flags.optimize >=2:
2422 # Skip doctests when running with -O2
2423 suite = _DocTestSuite()
2424 suite.addTest(SkipDocTestCase(module))
2425 return suite
2426
2427 tests.sort()
2428 suite = _DocTestSuite()
2429
2430 for test in tests:
2431 if len(test.examples) == 0:
2432 continue
2433 if not test.filename:
2434 filename = module.__file__
2435 if filename[-4:] == ".pyc":

Callers

nothing calls this directly

Calls 8

findMethod · 0.95
DocTestFinderClass · 0.85
_normalize_moduleFunction · 0.85
_DocTestSuiteClass · 0.85
SkipDocTestCaseClass · 0.85
DocTestCaseClass · 0.85
addTestMethod · 0.80
sortMethod · 0.45

Tested by

no test coverage detected