bpo-36406: Handle namespace packages in doctest (GH-12520)

This commit is contained in:
Xtreak 2019-12-13 23:36:53 +05:30 committed by Brett Cannon
parent 025a602af7
commit 8289e27393
3 changed files with 8 additions and 2 deletions

View File

@ -1059,7 +1059,8 @@ class DocTestFinder:
if module is None:
filename = None
else:
filename = getattr(module, '__file__', module.__name__)
# __file__ can be None for namespace packages.
filename = getattr(module, '__file__', None) or module.__name__
if filename[-4:] == ".pyc":
filename = filename[:-1]
return self._parser.get_doctest(docstring, globs, name,

View File

@ -701,8 +701,12 @@ class TestDocTestFinder(unittest.TestCase):
finally:
support.forget(pkg_name)
sys.path.pop()
assert doctest.DocTestFinder().find(mod) == []
include_empty_finder = doctest.DocTestFinder(exclude_empty=False)
exclude_empty_finder = doctest.DocTestFinder(exclude_empty=True)
self.assertEqual(len(include_empty_finder.find(mod)), 1)
self.assertEqual(len(exclude_empty_finder.find(mod)), 0)
def test_DocTestParser(): r"""
Unit tests for the `DocTestParser` class.

View File

@ -0,0 +1 @@
Handle namespace packages in :mod:`doctest`. Patch by Karthikeyan Singaravelan.