summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-09-10 14:16:46 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-09-10 14:16:46 (GMT)
commitc3bfb01a959235135c727d532e3e89bbf2658a09 (patch)
tree2f6dd0d97ea06d535f7b4349c28df02b7635396d /Lib/test/test_doctest.py
parentb83b287f17aa8f59e378f9d6ff77401c42d36dd3 (diff)
parent5abd76a75d633a1ba6f5fcc66b0bc4799b9e2eaa (diff)
downloadcpython-c3bfb01a959235135c727d532e3e89bbf2658a09.zip
cpython-c3bfb01a959235135c727d532e3e89bbf2658a09.tar.gz
cpython-c3bfb01a959235135c727d532e3e89bbf2658a09.tar.bz2
Merge #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.py25
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()