diff --git a/_pytest/doctest.py b/_pytest/doctest.py index 87ecca7b3..737ffe011 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -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) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index a4532dbeb..d880fdef2 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -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)