找不到参数的夹具
Fixture not found for parameter
我正在尝试 运行 我的 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 视为固定装置?相同的名称未用作函数名称。
由于您为其指定的名称,testConfiguration 似乎被视为测试。如果您传递给测试的所有参数不是来自测试示例中的参数化,则它们将被视为固定装置。要解决它,只需将您的函数重命名为 getTesttestConfiguration() 左右。
作为旁注,在 python 中通常使用蜗牛式表示法,而不是您选择的驼峰式表示法。
我正在尝试 运行 我的 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 视为固定装置?相同的名称未用作函数名称。
由于您为其指定的名称,testConfiguration 似乎被视为测试。如果您传递给测试的所有参数不是来自测试示例中的参数化,则它们将被视为固定装置。要解决它,只需将您的函数重命名为 getTesttestConfiguration() 左右。 作为旁注,在 python 中通常使用蜗牛式表示法,而不是您选择的驼峰式表示法。