【问题标题】:pytest doctest with fixtures in conftest.pypytest doctest 与 conftest.py 中的固定装置
【发布时间】:2014-10-28 11:24:18
【问题描述】:

我尝试在 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

知道这里有什么问题。

【问题讨论】:

    标签: pytest doctest


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 2022-08-02
      相关资源
      最近更新 更多