We use py.test in a project and use fixtures for most test cases. But I see no possibility to use fixtures in doctest files.
To give an example with some code snippets: I have a browser fixture in conftest.py like:
@fixture
def browser(request):
from wsgi_intercept import zope_testbrowser
browser = zope_testbrowser.WSGI_Browser()
[...]
return browser
and use it in the file test_browser.txt like:
>>> browser.open('some_url')
>>> browser.url == 'some_url'
True
But I can’t see a way to get the fixture into a doctest file. Is this possible at all with py.test?
It isn’t supported at the moment. pytest would need to know at collection time which fixtures are going to be used in a doctest. If we can come up with a way to declare which fixtures are going to be used, it shouldn’t be hard to add support to
_pytest/doctest.pyMaybe it’s also possible to automatically find out which fixtures a doctest needs, not sure.