fix issue275 - allow usefixtures and autouse fixtures

for running doctest text files.
This commit is contained in:
holger krekel 2013-11-22 15:35:20 +01:00
parent 4031588811
commit c0dd7c5975
4 changed files with 33 additions and 1 deletions

View File

@ -29,6 +29,9 @@ Unreleased
- don't hide an ImportError when importing a plugin produces one.
fixes issue375.
- fix issue275 - allow usefixtures and autouse fixtures
for running doctest text files.
- fix issue380 by making --resultlog only rely on longrepr instead
of the "reprcrash" attribute which only exists sometimes.

View File

@ -91,8 +91,13 @@ class DoctestTextfile(DoctestItem, pytest.File):
doctest = py.std.doctest
# satisfy `FixtureRequest` constructor...
self.funcargs = {}
self._fixtureinfo = FuncFixtureInfo((), [], {})
fm = self.session._fixturemanager
def func():
pass
self._fixtureinfo = fm.getfixtureinfo(node=self, func=func,
cls=None, funcargs=False)
fixture_request = FixtureRequest(self)
fixture_request._fillfixtures()
failed, tot = doctest.testfile(
str(self.fspath), module_relative=False,
optionflags=doctest.ELLIPSIS,

View File

@ -56,3 +56,7 @@ It is possible to use fixtures using the ``getfixture`` helper::
# content of example.rst
>>> tmp = getfixture('tmpdir')
>>> ...
>>>
Also, :ref:`usefixtures` and :ref:`autouse` fixtures are supported
when executing text doctest files.

View File

@ -209,6 +209,26 @@ class TestDoctests:
reprec = testdir.inline_run(p, )
reprec.assertoutcome(passed=1)
@xfail_if_pdbpp_installed
def test_txtfile_with_usefixtures_in_ini(self, testdir):
testdir.makeini("""
[pytest]
usefixtures = myfixture
""")
testdir.makeconftest("""
import pytest
@pytest.fixture
def myfixture(monkeypatch):
monkeypatch.setenv("HELLO", "WORLD")
""")
p = testdir.maketxtfile("""
>>> import os
>>> os.environ["HELLO"]
'WORLD'
""")
reprec = testdir.inline_run(p, )
reprec.assertoutcome(passed=1)
@xfail_if_pdbpp_installed
def test_doctestmodule_with_fixtures(self, testdir):