diff options
| author | R David Murray <rdmurray@bitdance.com> | 2012-09-10 14:17:13 (GMT) |
|---|---|---|
| committer | R David Murray <rdmurray@bitdance.com> | 2012-09-10 14:17:13 (GMT) |
| commit | 8d580539f0765fd39a457d85a68bf2d4a2f1099f (patch) | |
| tree | 7968d0c3caf8d4fcd9ca4b672f131fbe1f2dba6f /Lib/test/test_doctest.py | |
| parent | 7a8634d8d86041e47b283717424eb2b3cede8c84 (diff) | |
| download | cpython-8d580539f0765fd39a457d85a68bf2d4a2f1099f.zip cpython-8d580539f0765fd39a457d85a68bf2d4a2f1099f.tar.gz cpython-8d580539f0765fd39a457d85a68bf2d4a2f1099f.tar.bz2 | |
#14649: clarify DocTestSuite error when there are no docstrings.
Also adds tests to verify the documented behavior (which is probably a bug, as
indicated in the added comments).
Patch by Chris Jerdonek.
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 9b500fd..8c87bee 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -2006,6 +2006,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() |
