bpo-36406: Handle namespace packages in doctest (GH-12520)
This commit is contained in:
parent
025a602af7
commit
8289e27393
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Handle namespace packages in :mod:`doctest`. Patch by Karthikeyan Singaravelan.
|
Loading…
Reference in New Issue