【问题标题】:Fixture not found for parameter未找到参数的夹具
【发布时间】:2022-01-18 08:39:46
【问题描述】:

我正在尝试运行我的 pytest 参数化测试。

def testConfiguration(numberOfSmall, numberOfMedium, numberOfLarge,numaValue):
   ...

@pytest.mark.parametrize("small, medium, large, numaValue, out", [
(0,0,1,0,True),
(0,0,1,1,True),
(0,0,2,0,True),
(1,1,1,0,True),
(0,1,1,0,True),
(1,0,1,0,True),
(0,1,0,0,True),
(0,1,0,1,True),
(0,2,0,0,True),
(2,2,0,0,True),
(2,1,0,0,True),
(1,0,0,0,True),
(1,0,0,1,True),
(2,0,0,0,True),
(2,0,0,1,True),
(3,0,0,0,True),
(3,0,0,1,True),
(4,0,0,0,True),
(4,1,0,0,True),
(5,0,0,0,True),
(6,0,0,0,True),
])
def testAll(small, medium, large, numaValue, out):
    assert testConfiguration(small, medium, large, numaValue) == out

但是,当我这样做时,我在 pytest 中收到此错误。

E       fixture 'numberOfSmall' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

请注意,该错误是非致命的,程序的其余部分将正常执行。

为什么 numberOfSmall 被视为固定装置?同名没有被用作函数名。

【问题讨论】:

    标签: python python-2.7 pytest


    【解决方案1】:

    由于您给它起的名字,看起来 testConfiguration 被认为是一个测试。如果您传递给测试的所有参数不是来自测试示例中的参数化,则它们都被视为固定装置。要解决它,只需将您的函数重命名为 getTesttestConfiguration() 左右。 附带说明一下,在 python 中,通常使用蜗牛大小写表示法,而不是您选择的骆驼大小写表示法。

    【讨论】:

    • 是的,就是这样。重命名为 executeConfiguration 并且它起作用了。谢谢
    猜你喜欢
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 2023-01-25
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    相关资源
    最近更新 更多