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 name of
(module=None, globs=None, extraglobs=None, test_finder=None,
**options)
| 2541 | |
| 2542 | |
| 2543 | def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None, |
| 2544 | **options): |
| 2545 | """ |
| 2546 | Convert doctest tests for a module to a unittest test suite. |
| 2547 | |
| 2548 | This converts each documentation string in a module that |
| 2549 | contains doctest tests to a unittest test case. If any of the |
| 2550 | tests in a doc string fail, then the test case fails. An exception |
| 2551 | is raised showing the name of the file containing the test and a |
| 2552 | (sometimes approximate) line number. |
| 2553 | |
| 2554 | The `module` argument provides the module to be tested. The argument |
| 2555 | can be either a module or a module name. |
| 2556 | |
| 2557 | If no argument is given, the calling module is used. |
| 2558 | |
| 2559 | A number of options may be provided as keyword arguments: |
| 2560 | |
| 2561 | setUp |
| 2562 | A set-up function. This is called before running the |
| 2563 | tests in each file. The setUp function will be passed a DocTest |
| 2564 | object. The setUp function can access the test globals as the |
| 2565 | globs attribute of the test passed. |
| 2566 | |
| 2567 | tearDown |
| 2568 | A tear-down function. This is called after running the |
| 2569 | tests in each file. The tearDown function will be passed a DocTest |
| 2570 | object. The tearDown function can access the test globals as the |
| 2571 | globs attribute of the test passed. |
| 2572 | |
| 2573 | globs |
| 2574 | A dictionary containing initial global variables for the tests. |
| 2575 | |
| 2576 | optionflags |
| 2577 | A set of doctest option flags expressed as an integer. |
| 2578 | """ |
| 2579 | |
| 2580 | if test_finder is None: |
| 2581 | test_finder = DocTestFinder() |
| 2582 | |
| 2583 | module = _normalize_module(module) |
| 2584 | tests = test_finder.find(module, globs=globs, extraglobs=extraglobs) |
| 2585 | |
| 2586 | if not tests and sys.flags.optimize >=2: |
| 2587 | # Skip doctests when running with -O2 |
| 2588 | suite = _DocTestSuite() |
| 2589 | suite.addTest(SkipDocTestCase(module)) |
| 2590 | return suite |
| 2591 | |
| 2592 | tests.sort() |
| 2593 | suite = _DocTestSuite() |
| 2594 | |
| 2595 | for test in tests: |
| 2596 | if len(test.examples) == 0: |
| 2597 | continue |
| 2598 | if not test.filename: |
| 2599 | filename = module.__file__ |
| 2600 | if filename[-4:] == ".pyc": |
no test coverage detected
searching dependent graphs…