mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
#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.
This commit is contained in:
parent
01beb69c7d
commit
5abd76a75d
6 changed files with 84 additions and 6 deletions
|
@ -1984,6 +1984,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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue