pass fixture request object (and convenience shortcut to get fixtures) into doctest files

--HG--
branch : doctest-fixtures
This commit is contained in:
Andreas Zeidler 2013-01-30 17:32:37 +01:00
parent 64e6c71bf6
commit 25547e3afb
1 changed files with 7 additions and 0 deletions

View File

@ -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):