gpt4 book ai didi

pytest doctest 与 conftest.py 中的固定装置

转载 作者:行者123 更新时间:2023-12-04 16:45:03 26 4
gpt4 key购买 nike

我尝试在 py.test 文档测试中使用固定装置。文档中有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

知道这里有什么问题。

最佳答案

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

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!

关于pytest doctest 与 conftest.py 中的固定装置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25653147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com