diff --git a/CHANGELOG b/CHANGELOG index 5c66a8772..e39490049 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +Changes between 1.3.3 and XXX +================================================== + +- fix issue116: --doctestmodules works in the presence of __init__.py files as well + Changes between 1.3.2 and 1.3.3 ================================================== diff --git a/py/_path/local.py b/py/_path/local.py index 0e051eb8d..1765b80ff 100644 --- a/py/_path/local.py +++ b/py/_path/local.py @@ -519,6 +519,8 @@ class LocalPath(FSBase): pkg = __import__(pkgpath.basename, None, None, []) names = self.new(ext='').relto(pkgpath.dirpath()) names = names.split(self.sep) + if names and names[-1] == "__init__": + names.pop() modname = ".".join(names) else: # no package scope, still make it possible @@ -532,7 +534,8 @@ class LocalPath(FSBase): elif modfile.endswith('$py.class'): modfile = modfile[:-9] + '.py' if modfile.endswith("__init__.py"): - modfile = modfile[:-12] + if self.basename != "__init__.py": + modfile = modfile[:-12] if not self.samefile(modfile): raise self.ImportMismatchError(modname, modfile, self) return mod diff --git a/testing/path/test_local.py b/testing/path/test_local.py index e13a4899c..5b296288b 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -306,9 +306,11 @@ class TestImport: def test_pyimport_dir(self, tmpdir): p = tmpdir.join("hello_123") - p.ensure("__init__.py") + p_init = p.ensure("__init__.py") m = p.pyimport() assert m.__name__ == "hello_123" + m = p_init.pyimport() + assert m.__name__ == "hello_123" def test_pyimport_execfile_different_name(self, path1): obj = path1.join('execfile.py').pyimport(modname="0x.y.z") diff --git a/testing/plugin/test_pytest_doctest.py b/testing/plugin/test_pytest_doctest.py index 161ddf44f..ae13ef69b 100644 --- a/testing/plugin/test_pytest_doctest.py +++ b/testing/plugin/test_pytest_doctest.py @@ -1,4 +1,5 @@ from py._plugin.pytest_doctest import DoctestModule, DoctestTextfile +import py pytest_plugins = ["pytest_doctest"] @@ -73,16 +74,16 @@ class TestDoctests: reprec = testdir.inline_run(p, "--doctest-modules") reprec.assertoutcome(failed=1) - def test_doctestmodule_external(self, testdir): - p = testdir.makepyfile(""" - # + def test_doctestmodule_external_and_issue116(self, testdir): + p = testdir.mkpydir("hello") + p.join("__init__.py").write(py.code.Source(""" def somefunc(): ''' >>> i = 0 >>> i + 1 2 ''' - """) + """)) result = testdir.runpytest(p, "--doctest-modules") result.stdout.fnmatch_lines([ '004 *>>> i = 0',