我正在尝试使用 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/