diff -r ab4432daf69f Lib/doctest.py --- a/Lib/doctest.py Mon Oct 22 21:50:27 2012 -0700 +++ b/Lib/doctest.py Tue Oct 23 14:53:02 2012 +0300 @@ -2321,7 +2321,8 @@ """ if test_finder is None: - test_finder = DocTestFinder() + # By default, create empty tests for files without docstrings + test_finder = DocTestFinder(exclude_empty=False) module = _normalize_module(module) tests = test_finder.find(module, globs=globs, extraglobs=extraglobs) @@ -2336,9 +2337,7 @@ # otherwise be hidden. # It is probably a bug that this exception is not also raised if the # number of doctest examples in tests is zero (i.e. if no doctest - # examples were found). However, we should probably not be raising - # an exception at all here, though it is too late to make this change - # for a maintenance release. See also issue #14649. + # examples were found). See also issue #14649. raise ValueError(module, "has no docstrings") tests.sort() diff -r ab4432daf69f Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py Mon Oct 22 21:50:27 2012 -0700 +++ b/Lib/test/test_doctest.py Tue Oct 23 14:53:02 2012 +0300 @@ -1992,25 +1992,25 @@ >>> suite.run(unittest.TestResult()) - However, if DocTestSuite finds no docstrings, it raises an error: + The module need not contain any docstrings either: + >>> suite = doctest.DocTestSuite('test.sample_doctest_no_docstrings') + >>> suite.run(unittest.TestResult()) + + + If you want an error in this case, you can pass a DocTestFinder + instance without the `exclude_empty` keyword argument set to False: + + >>> finder = doctest.DocTestFinder() >>> try: - ... doctest.DocTestSuite('test.sample_doctest_no_docstrings') + ... doctest.DocTestSuite('test.sample_doctest_no_docstrings', + ... test_finder=finder) ... 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()) - - We can use the current module: >>> suite = test.sample_doctest.test_suite()