Add option to ignore import errors in doctests
--HG-- branch : ignore-doctest-import-errors
This commit is contained in:
parent
394367e1d2
commit
f2ca0b8170
|
@ -17,6 +17,10 @@ def pytest_addoption(parser):
|
||||||
action="store", default="test*.txt", metavar="pat",
|
action="store", default="test*.txt", metavar="pat",
|
||||||
help="doctests file matching pattern, default: test*.txt",
|
help="doctests file matching pattern, default: test*.txt",
|
||||||
dest="doctestglob")
|
dest="doctestglob")
|
||||||
|
group.addoption("--doctest-ignore-import-errors",
|
||||||
|
action="store_true", default=False,
|
||||||
|
help="ignore doctest ImportErrors",
|
||||||
|
dest="doctest_ignore_import_errors")
|
||||||
|
|
||||||
def pytest_collect_file(path, parent):
|
def pytest_collect_file(path, parent):
|
||||||
config = parent.config
|
config = parent.config
|
||||||
|
@ -130,7 +134,13 @@ class DoctestModule(pytest.File):
|
||||||
if self.fspath.basename == "conftest.py":
|
if self.fspath.basename == "conftest.py":
|
||||||
module = self.config._conftest.importconftest(self.fspath)
|
module = self.config._conftest.importconftest(self.fspath)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
module = self.fspath.pyimport()
|
module = self.fspath.pyimport()
|
||||||
|
except ImportError:
|
||||||
|
if self.config.getvalue('doctest_ignore_import_errors'):
|
||||||
|
pytest.skip('unable to import module %r' % self.fspath)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
# satisfy `FixtureRequest` constructor...
|
# satisfy `FixtureRequest` constructor...
|
||||||
self.funcargs = {}
|
self.funcargs = {}
|
||||||
self._fixtureinfo = FuncFixtureInfo((), [], {})
|
self._fixtureinfo = FuncFixtureInfo((), [], {})
|
||||||
|
|
Loading…
Reference in New Issue