Merge pull request #10088 from alicederyn/doctest.importmode
Pass importmode to import_path in DoctestModule
This commit is contained in:
commit
7dcabc1f49
1
AUTHORS
1
AUTHORS
|
@ -15,6 +15,7 @@ Alan Velasco
|
||||||
Alexander Johnson
|
Alexander Johnson
|
||||||
Alexander King
|
Alexander King
|
||||||
Alexei Kozlenok
|
Alexei Kozlenok
|
||||||
|
Alice Purcell
|
||||||
Allan Feldman
|
Allan Feldman
|
||||||
Aly Sivji
|
Aly Sivji
|
||||||
Amir Elkess
|
Amir Elkess
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Doctests now respect the ``--import-mode`` flag.
|
|
@ -542,7 +542,11 @@ class DoctestModule(pytest.Module):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
module = import_path(self.path, root=self.config.rootpath)
|
module = import_path(
|
||||||
|
self.path,
|
||||||
|
root=self.config.rootpath,
|
||||||
|
mode=self.config.getoption("importmode"),
|
||||||
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if self.config.getvalue("doctest_ignore_import_errors"):
|
if self.config.getvalue("doctest_ignore_import_errors"):
|
||||||
pytest.skip("unable to import module %r" % self.path)
|
pytest.skip("unable to import module %r" % self.path)
|
||||||
|
|
|
@ -113,6 +113,28 @@ class TestDoctests:
|
||||||
reprec = pytester.inline_run(p)
|
reprec = pytester.inline_run(p)
|
||||||
reprec.assertoutcome(failed=1)
|
reprec.assertoutcome(failed=1)
|
||||||
|
|
||||||
|
def test_importmode(self, pytester: Pytester):
|
||||||
|
p = pytester.makepyfile(
|
||||||
|
**{
|
||||||
|
"namespacepkg/innerpkg/__init__.py": "",
|
||||||
|
"namespacepkg/innerpkg/a.py": """
|
||||||
|
def some_func():
|
||||||
|
return 42
|
||||||
|
""",
|
||||||
|
"namespacepkg/innerpkg/b.py": """
|
||||||
|
from namespacepkg.innerpkg.a import some_func
|
||||||
|
def my_func():
|
||||||
|
'''
|
||||||
|
>>> my_func()
|
||||||
|
42
|
||||||
|
'''
|
||||||
|
return some_func()
|
||||||
|
""",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
reprec = pytester.inline_run(p, "--doctest-modules", "--import-mode=importlib")
|
||||||
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
||||||
def test_new_pattern(self, pytester: Pytester):
|
def test_new_pattern(self, pytester: Pytester):
|
||||||
p = pytester.maketxtfile(
|
p = pytester.maketxtfile(
|
||||||
xdoc="""
|
xdoc="""
|
||||||
|
|
Loading…
Reference in New Issue