fix issue116 : --doctestmodules also works in the presence of __init__.py files, done by fixing the underlyingly used path.pyimport()
--HG-- branch : trunk
This commit is contained in:
parent
d8fcc96563
commit
95bafbccd1
|
@ -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
|
Changes between 1.3.2 and 1.3.3
|
||||||
==================================================
|
==================================================
|
||||||
|
|
||||||
|
|
|
@ -519,6 +519,8 @@ class LocalPath(FSBase):
|
||||||
pkg = __import__(pkgpath.basename, None, None, [])
|
pkg = __import__(pkgpath.basename, None, None, [])
|
||||||
names = self.new(ext='').relto(pkgpath.dirpath())
|
names = self.new(ext='').relto(pkgpath.dirpath())
|
||||||
names = names.split(self.sep)
|
names = names.split(self.sep)
|
||||||
|
if names and names[-1] == "__init__":
|
||||||
|
names.pop()
|
||||||
modname = ".".join(names)
|
modname = ".".join(names)
|
||||||
else:
|
else:
|
||||||
# no package scope, still make it possible
|
# no package scope, still make it possible
|
||||||
|
@ -532,7 +534,8 @@ class LocalPath(FSBase):
|
||||||
elif modfile.endswith('$py.class'):
|
elif modfile.endswith('$py.class'):
|
||||||
modfile = modfile[:-9] + '.py'
|
modfile = modfile[:-9] + '.py'
|
||||||
if modfile.endswith("__init__.py"):
|
if modfile.endswith("__init__.py"):
|
||||||
modfile = modfile[:-12]
|
if self.basename != "__init__.py":
|
||||||
|
modfile = modfile[:-12]
|
||||||
if not self.samefile(modfile):
|
if not self.samefile(modfile):
|
||||||
raise self.ImportMismatchError(modname, modfile, self)
|
raise self.ImportMismatchError(modname, modfile, self)
|
||||||
return mod
|
return mod
|
||||||
|
|
|
@ -306,9 +306,11 @@ class TestImport:
|
||||||
|
|
||||||
def test_pyimport_dir(self, tmpdir):
|
def test_pyimport_dir(self, tmpdir):
|
||||||
p = tmpdir.join("hello_123")
|
p = tmpdir.join("hello_123")
|
||||||
p.ensure("__init__.py")
|
p_init = p.ensure("__init__.py")
|
||||||
m = p.pyimport()
|
m = p.pyimport()
|
||||||
assert m.__name__ == "hello_123"
|
assert m.__name__ == "hello_123"
|
||||||
|
m = p_init.pyimport()
|
||||||
|
assert m.__name__ == "hello_123"
|
||||||
|
|
||||||
def test_pyimport_execfile_different_name(self, path1):
|
def test_pyimport_execfile_different_name(self, path1):
|
||||||
obj = path1.join('execfile.py').pyimport(modname="0x.y.z")
|
obj = path1.join('execfile.py').pyimport(modname="0x.y.z")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from py._plugin.pytest_doctest import DoctestModule, DoctestTextfile
|
from py._plugin.pytest_doctest import DoctestModule, DoctestTextfile
|
||||||
|
import py
|
||||||
|
|
||||||
pytest_plugins = ["pytest_doctest"]
|
pytest_plugins = ["pytest_doctest"]
|
||||||
|
|
||||||
|
@ -73,16 +74,16 @@ class TestDoctests:
|
||||||
reprec = testdir.inline_run(p, "--doctest-modules")
|
reprec = testdir.inline_run(p, "--doctest-modules")
|
||||||
reprec.assertoutcome(failed=1)
|
reprec.assertoutcome(failed=1)
|
||||||
|
|
||||||
def test_doctestmodule_external(self, testdir):
|
def test_doctestmodule_external_and_issue116(self, testdir):
|
||||||
p = testdir.makepyfile("""
|
p = testdir.mkpydir("hello")
|
||||||
#
|
p.join("__init__.py").write(py.code.Source("""
|
||||||
def somefunc():
|
def somefunc():
|
||||||
'''
|
'''
|
||||||
>>> i = 0
|
>>> i = 0
|
||||||
>>> i + 1
|
>>> i + 1
|
||||||
2
|
2
|
||||||
'''
|
'''
|
||||||
""")
|
"""))
|
||||||
result = testdir.runpytest(p, "--doctest-modules")
|
result = testdir.runpytest(p, "--doctest-modules")
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
'004 *>>> i = 0',
|
'004 *>>> i = 0',
|
||||||
|
|
Loading…
Reference in New Issue