Closed
Description
Here is a weird issue to track down and run. When you have a file with multiple doctests the tests will start failing if another test runs in between them. See the example below.
# code.py
def a():
"""
>>> getfixture("foo")
"""
def b():
"""
>>> getfixture("foo")
"""
# conftest.py
import pytest
@pytest.fixture
def foo():
pass
# test.py
def test_func(foo):
pass
% py.test --version
This is pytest version 2.7.2, imported from /Users/kevincox/.virtualenvs/starscream/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
pytest-ipdb-0.1-prerelease2 at /Users/kevincox/.virtualenvs/starscream/lib/python2.7/site-packages/pytestipdb/ptipdb.pyc
pytest-random-0.02 at /Users/kevincox/.virtualenvs/starscream/lib/python2.7/site-packages/random_plugin.pyc
% py.test --random --random-seed 368666649299 -vv --doctest-modules test.py code.py
================================================= test session starts =================================================
platform darwin -- Python 2.7.9 -- py-1.4.30 -- pytest-2.7.2 -- /Users/kevincox/.virtualenvs/starscream/bin/python2.7
Tests are shuffled using seed number 368666649299.
rootdir: /Users/kevincox, inifile:
plugins: ipdb, random
collected 3 items
code.py::code.a PASSED
test.py::test_func PASSED
code.py::code.b FAILED
====================================================== FAILURES =======================================================
__________________________________________________ [doctest] code.b ___________________________________________________
006 """
007 >>> getfixture("foo")
UNEXPECTED EXCEPTION: AttributeError("FixtureDef instance has no attribute 'cached_result'",)
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 1315, in __run
compileflags, 1) in test.globs
File "<doctest code.b[0]>", line 1, in <module>
File "/Users/kevincox/.virtualenvs/starscream/lib/python2.7/site-packages/_pytest/python.py", line 1385, in getfuncargvalue
return self._get_active_fixturedef(argname).cached_result[0]
AttributeError: FixtureDef instance has no attribute 'cached_result'
/Users/kevincox/code.py:7: UnexpectedException
========================================= 1 failed, 2 passed in 0.02 seconds ==========================================
% echo $?
1