mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
#15916: if there are no docstrings, make empty suite, not an error.
This makes doctest work like unittest: if the test case is empty, that just means there are zero tests run, it's not an error. The existing behavior was broken, since it only gave an error if there were *no* docstrings, and zero tests run if there were docstrings but none of them contained tests. So this makes it self-consistent as well. Patch by Glenn Jones.
This commit is contained in:
parent
865d23d1dd
commit
1976d9bf6d
6 changed files with 29 additions and 33 deletions
|
|
@ -2096,22 +2096,9 @@ def test_DocTestSuite():
|
|||
>>> suite.run(unittest.TestResult())
|
||||
<unittest.result.TestResult run=0 errors=0 failures=0>
|
||||
|
||||
However, if DocTestSuite finds no docstrings, it raises an error:
|
||||
The module need not contain any docstrings either:
|
||||
|
||||
>>> 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 = doctest.DocTestSuite('test.sample_doctest_no_docstrings')
|
||||
>>> suite.run(unittest.TestResult())
|
||||
<unittest.result.TestResult run=0 errors=0 failures=0>
|
||||
|
||||
|
|
@ -2121,6 +2108,22 @@ def test_DocTestSuite():
|
|||
>>> suite.run(unittest.TestResult())
|
||||
<unittest.result.TestResult run=9 errors=0 failures=4>
|
||||
|
||||
We can also provide a DocTestFinder:
|
||||
|
||||
>>> finder = doctest.DocTestFinder()
|
||||
>>> suite = doctest.DocTestSuite('test.sample_doctest',
|
||||
... test_finder=finder)
|
||||
>>> suite.run(unittest.TestResult())
|
||||
<unittest.result.TestResult run=9 errors=0 failures=4>
|
||||
|
||||
The DocTestFinder need not return any tests:
|
||||
|
||||
>>> finder = doctest.DocTestFinder()
|
||||
>>> 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 supply global variables. If we pass globs, they will be
|
||||
used instead of the module globals. Here we'll pass an empty
|
||||
globals, triggering an extra error:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue