python - pytest 找不到 pytest.fixture_request

标签 python pytest

我正在尝试使用 alternative approach在此处的 PyTest 文档中列出。我的 parametrize 装饰器调用如下所示

@pytest.mark.parametrize("val1, params, result", [
    ('a string', pytest.fixture_request('valid_type'), 150)

])

但是,当我运行 pytest 时,出现以下错误:

test_get_responses.py:102: in <module>
    ('a string', pytest.fixture_request('valid_type'), 150)
E   AttributeError: 'module' object has no attribute 'fixture_request'

valid_type fixture 确实存在。

我正在运行 pytest 版本 3.2.0

如何解决这个问题,以便我可以使用上面文档中列出的“替代方法”?

最佳答案

所描述的方法只是一个尚未实现的提议(正如您在此讨论中看到的:https://github.com/pytest-dev/pytest/issues/349#issuecomment-286451346)。作为解决方法,您可以使用包 pytest-lazy-fixture(可以使用 pip 安装):而不是 pytest.fixture_request('fixture_name') 只需使用 pytest.lazy_fixture('fixture_name')

关于python - pytest 找不到 pytest.fixture_request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45576850/

相关文章:

python - Flask + VueJs 项目的 Docker 多阶段

python - 测试覆盖 Nose vs pytest

python-3.x - 在 Python Azure 函数中,如何仅用一行代码将共享库导入到我的函数中?

python - 将测试标记为从 pytest 中的 fixture 内部通过

python - 如何在测试(或方法)中自动使用 pytest fixture ?

python - pytest - 如何将 pytest_addoption 值传递给 pytest 参数化?

python - im7图像文件到openCV

python - Scapy设置类属性问题

javascript - 通过 flask 将谷歌图表的列表信息正确发送到 JS?

Python请求失败但Postman返回200