From 25547e3afbfa8be57ae6030eebc181a152d4f29c Mon Sep 17 00:00:00 2001 From: Andreas Zeidler Date: Wed, 30 Jan 2013 17:32:37 +0100 Subject: [PATCH] pass fixture request object (and convenience shortcut to get fixtures) into doctest files --HG-- branch : doctest-fixtures --- _pytest/doctest.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/_pytest/doctest.py b/_pytest/doctest.py index aaebab78e..e447b8faf 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -1,6 +1,7 @@ """ discover and run doctests in modules and test files.""" import pytest, py +from _pytest.python import FixtureRequest, FuncFixtureInfo from py._code.code import TerminalRepr, ReprFileLocation def pytest_addoption(parser): @@ -70,9 +71,15 @@ class DoctestItem(pytest.Item): class DoctestTextfile(DoctestItem, pytest.File): def runtest(self): doctest = py.std.doctest + # satisfy `FixtureRequest` constructor... + self.funcargs = {} + self._fixtureinfo = FuncFixtureInfo((), [], {}) + fixture_request = FixtureRequest(self) failed, tot = doctest.testfile( str(self.fspath), module_relative=False, optionflags=doctest.ELLIPSIS, + extraglobs=dict(fixture_request=fixture_request, + get_fixture=fixture_request.getfuncargvalue), raise_on_error=True, verbose=0) class DoctestModule(DoctestItem, pytest.File):