在conftest.py中使用fixtures进行pytest doctest

时间:2014-09-03 20:34:02

标签: pytest doctest

我尝试在py.test doctests中使用fixture。 在文档中是getfixture函数,可以直接在doctests中使用。

getfixture('tmpdir')

这可以按预期工作。

现在我尝试使用我自己在conftest.py中定义的灯具。 当我运行py.test --fixtures时,我会看到我的灯具。 但是当我尝试在doctest中获得我的装置时,我得到了这个消息。

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

知道这里有什么问题。

1 个答案:

答案 0 :(得分:0)

您没有将 conftest.py 与您正在测试的文件放在一起吗? pytest doc 说:

<块引用>

请注意,与普通的 conftest.py 一样,fixture 是在 conftest 所在的目录树中发现的。这意味着如果您将 doctest 与源代码放在一起,则相关的 conftest.py 需要位于同一目录树中。 不会在同级目录树中发现固件

相关问题