also provide `get_fixture` helper for module level doctests
--HG-- branch : doctest-fixtures
This commit is contained in:
parent
c4b3a09886
commit
5a3547dd7e
|
@ -88,6 +88,11 @@ class DoctestModule(DoctestItem, pytest.File):
|
||||||
module = self.config._conftest.importconftest(self.fspath)
|
module = self.config._conftest.importconftest(self.fspath)
|
||||||
else:
|
else:
|
||||||
module = self.fspath.pyimport()
|
module = self.fspath.pyimport()
|
||||||
|
# satisfy `FixtureRequest` constructor...
|
||||||
|
self.funcargs = {}
|
||||||
|
self._fixtureinfo = FuncFixtureInfo((), [], {})
|
||||||
|
fixture_request = FixtureRequest(self)
|
||||||
failed, tot = doctest.testmod(
|
failed, tot = doctest.testmod(
|
||||||
module, raise_on_error=True, verbose=0,
|
module, raise_on_error=True, verbose=0,
|
||||||
|
extraglobs=dict(get_fixture=fixture_request.getfuncargvalue),
|
||||||
optionflags=doctest.ELLIPSIS)
|
optionflags=doctest.ELLIPSIS)
|
||||||
|
|
|
@ -133,3 +133,14 @@ class TestDoctests:
|
||||||
""")
|
""")
|
||||||
reprec = testdir.inline_run(p, )
|
reprec = testdir.inline_run(p, )
|
||||||
reprec.assertoutcome(passed=1)
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
||||||
|
def test_doctestmodule_with_fixtures(self, testdir, tmpdir):
|
||||||
|
p = testdir.makepyfile("""
|
||||||
|
'''
|
||||||
|
>>> dir = get_fixture('tmpdir')
|
||||||
|
>>> type(dir).__name__
|
||||||
|
'LocalPath'
|
||||||
|
'''
|
||||||
|
""")
|
||||||
|
reprec = testdir.inline_run(p, "--doctest-modules")
|
||||||
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
Loading…
Reference in New Issue