pass fixture request object (and convenience shortcut to get fixtures) into doctest files
--HG-- branch : doctest-fixtures
This commit is contained in:
parent
64e6c71bf6
commit
25547e3afb
|
@ -1,6 +1,7 @@
|
||||||
""" discover and run doctests in modules and test files."""
|
""" discover and run doctests in modules and test files."""
|
||||||
|
|
||||||
import pytest, py
|
import pytest, py
|
||||||
|
from _pytest.python import FixtureRequest, FuncFixtureInfo
|
||||||
from py._code.code import TerminalRepr, ReprFileLocation
|
from py._code.code import TerminalRepr, ReprFileLocation
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
|
@ -70,9 +71,15 @@ class DoctestItem(pytest.Item):
|
||||||
class DoctestTextfile(DoctestItem, pytest.File):
|
class DoctestTextfile(DoctestItem, pytest.File):
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
doctest = py.std.doctest
|
doctest = py.std.doctest
|
||||||
|
# satisfy `FixtureRequest` constructor...
|
||||||
|
self.funcargs = {}
|
||||||
|
self._fixtureinfo = FuncFixtureInfo((), [], {})
|
||||||
|
fixture_request = FixtureRequest(self)
|
||||||
failed, tot = doctest.testfile(
|
failed, tot = doctest.testfile(
|
||||||
str(self.fspath), module_relative=False,
|
str(self.fspath), module_relative=False,
|
||||||
optionflags=doctest.ELLIPSIS,
|
optionflags=doctest.ELLIPSIS,
|
||||||
|
extraglobs=dict(fixture_request=fixture_request,
|
||||||
|
get_fixture=fixture_request.getfuncargvalue),
|
||||||
raise_on_error=True, verbose=0)
|
raise_on_error=True, verbose=0)
|
||||||
|
|
||||||
class DoctestModule(DoctestItem, pytest.File):
|
class DoctestModule(DoctestItem, pytest.File):
|
||||||
|
|
Loading…
Reference in New Issue