also provide `get_fixture` helper for module level doctests

--HG--
branch : doctest-fixtures
This commit is contained in:
Andreas Zeidler 2013-03-20 17:32:48 +01:00
parent c4b3a09886
commit 5a3547dd7e
2 changed files with 16 additions and 0 deletions

View File

@ -88,6 +88,11 @@ class DoctestModule(DoctestItem, pytest.File):
module = self.config._conftest.importconftest(self.fspath)
else:
module = self.fspath.pyimport()
# satisfy `FixtureRequest` constructor...
self.funcargs = {}
self._fixtureinfo = FuncFixtureInfo((), [], {})
fixture_request = FixtureRequest(self)
failed, tot = doctest.testmod(
module, raise_on_error=True, verbose=0,
extraglobs=dict(get_fixture=fixture_request.getfuncargvalue),
optionflags=doctest.ELLIPSIS)

View File

@ -133,3 +133,14 @@ class TestDoctests:
""")
reprec = testdir.inline_run(p, )
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)