diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-12-13 23:30:41 (GMT) |
---|---|---|
committer | Brett Cannon <54418+brettcannon@users.noreply.github.com> | 2019-12-13 23:30:41 (GMT) |
commit | aa74a53ad61134911ac7904f24fd2630aeaa8ac8 (patch) | |
tree | bb4ae7da7e82182b7e5eec868b1bff47c1c80e3b | |
parent | 3b18b17efcee6f968cf85c543254b3611311e9f4 (diff) | |
download | cpython-aa74a53ad61134911ac7904f24fd2630aeaa8ac8.zip cpython-aa74a53ad61134911ac7904f24fd2630aeaa8ac8.tar.gz cpython-aa74a53ad61134911ac7904f24fd2630aeaa8ac8.tar.bz2 |
bpo-36406: Handle namespace packages in doctest (GH-12520) (GH-17591)
(cherry picked from commit 8289e27393395ee903bd096d42e07c112d7f15c6)
Co-authored-by: Xtreak <tir.karthi@gmail.com>
-rw-r--r-- | Lib/doctest.py | 3 | ||||
-rw-r--r-- | Lib/test/test_doctest.py | 6 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-03-24-12-12-27.bpo-36406.mCEkOl.rst | 1 |
3 files changed, 8 insertions, 2 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index bf4889f..dcbcfe5 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -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, diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 5ea18f5..e37d842 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -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. diff --git a/Misc/NEWS.d/next/Library/2019-03-24-12-12-27.bpo-36406.mCEkOl.rst b/Misc/NEWS.d/next/Library/2019-03-24-12-12-27.bpo-36406.mCEkOl.rst new file mode 100644 index 0000000..3d81eb5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-03-24-12-12-27.bpo-36406.mCEkOl.rst @@ -0,0 +1 @@ +Handle namespace packages in :mod:`doctest`. Patch by Karthikeyan Singaravelan. |