diff options
| author | Benjamin Peterson <benjamin@python.org> | 2012-09-29 18:14:19 (GMT) |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2012-09-29 18:14:19 (GMT) |
| commit | 14fb44e1bab9db128770f1d91d244916a669e7c3 (patch) | |
| tree | 278d9ccc8f819b05f8114c3154087c70b88ed69c /Lib/test/test_doctest.py | |
| parent | 1764c80925795b6f059e961c5a352c5ece5a7fff (diff) | |
| parent | 99a247fd01c1cd780c0c3ee1116657627f1ee744 (diff) | |
| download | cpython-14fb44e1bab9db128770f1d91d244916a669e7c3.zip cpython-14fb44e1bab9db128770f1d91d244916a669e7c3.tar.gz cpython-14fb44e1bab9db128770f1d91d244916a669e7c3.tar.bz2 | |
merge mostly from default
Diffstat (limited to 'Lib/test/test_doctest.py')
| -rw-r--r-- | Lib/test/test_doctest.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 44b9554..8f8c7c7 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -1986,6 +1986,31 @@ def test_DocTestSuite(): >>> suite.run(unittest.TestResult()) <unittest.result.TestResult run=9 errors=0 failures=4> + The module need not contain any doctest examples: + + >>> suite = doctest.DocTestSuite('test.sample_doctest_no_doctests') + >>> suite.run(unittest.TestResult()) + <unittest.result.TestResult run=0 errors=0 failures=0> + + However, if DocTestSuite finds no docstrings, it raises an error: + + >>> try: + ... doctest.DocTestSuite('test.sample_doctest_no_docstrings') + ... except ValueError as e: + ... error = e + + >>> print(error.args[1]) + has no docstrings + + You can prevent this error by passing a DocTestFinder instance with + the `exclude_empty` keyword argument set to False: + + >>> finder = doctest.DocTestFinder(exclude_empty=False) + >>> suite = doctest.DocTestSuite('test.sample_doctest_no_docstrings', + ... test_finder=finder) + >>> suite.run(unittest.TestResult()) + <unittest.result.TestResult run=0 errors=0 failures=0> + We can use the current module: >>> suite = test.sample_doctest.test_suite() |
