我正在嘗試運行我的 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 被視為固定裝置?相同的名稱未用作函式名稱。
uj5u.com熱心網友回復:
由于您給它的名稱,它看起來像 testConfiguration 被認為是一個測驗。如果您傳遞給測驗的所有引數不是來自測驗示例中的引數化,則它們都被視為固定裝置。要解決它,只需將您的函式重命名為 getTesttestConfiguration() 左右。附帶說明一下,在 python 中,通常使用蝸牛大小寫表示法,而不是您選擇的駱駝大小寫表示法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/415924.html
標籤:
