i try to use fixtures in py.test doctests. In the documentation is the getfixture function which can be used in the doctests directly.
getfixture('tmpdir')
this works as expected.
Now i try to use my own fixtures which are defined in a conftest.py. I see my fixtures when i run py.test --fixtures. But when i try to get my fixture in the doctest i get this message.
008 >>> config = getfixture('config')
UNEXPECTED EXCEPTION: FixtureLookupError()
Traceback (most recent call last):
File "/Users/christian/local/lib/python2.7/doctest.py", line 1254, in __run
compileflags, 1) in test.globs
File "<doctest README.txt[2]>", line 1, in <module>
File "/Users/christian/.buildout/eggs/pytest-2.6.1-py2.7.egg/_pytest/python.py", line 1337, in getfuncargvalue
return self._get_active_fixturedef(argname).cached_result[0]
File "/Users/christian/.buildout/eggs/pytest-2.6.1-py2.7.egg/_pytest/python.py", line 1344, in _get_active_fixturedef
fixturedef = self._getnextfixturedef(argname)
File "/Users/christian/.buildout/eggs/pytest-2.6.1-py2.7.egg/_pytest/python.py", line 1202, in _getnextfixturedef
raise FixtureLookupError(argname, self)
FixtureLookupError
Any idea what's the problem here.
Are you not putting conftest.py alongside with your files that you are testing? The pytest doc says:
Note that like the normal conftest.py, the fixtures are discovered in the directory tree conftest is in. Meaning that if you put your doctest with your source code, the relevant conftest.py needs to be in the same directory tree. Fixtures will not be discovered in a sibling directory tree!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With