【发布时间】:2022-01-21 16:38:57
【问题描述】:
尝试在 PyCharm 中使用 pytest 测试文件,但我反复收到“未找到夹具 [变量名称]。关于此问题,我能找到的只是参数化拼写错误的情况。
liste_paie = []
def calculer_paie_employe(tauxh,heures):
total = tauxh * heures
impot = total * 0.20
net = total - impot
liste_paie = [heures, tauxh, total, impot, net]
return liste_paie
pytest.mark.parametrize("var1,var2,expected_1,expected_2,expected_3", [(14.7 , 25,367.5,73.5,294), (20 , 15, 300, 60, 240),
(15.6 , 23.9, 372.84, 75.568, 300)])
def test_calculer_paie_employe(var1,var2, expected_1, expected_2, expected_3):
calculer_paie_employe(var1,var2)
assert liste_paie[2] == expected_1 and liste_paie[3] == expected_2 and liste_paie[4] == expected_3
当我运行它时,我得到:
测试设置失败 E 夹具 'var1' 未找到 可用的固定装置:缓存、capfd、capfdbinary、caplog、capsys、capsysbinary、doctest_namespace、monkeypatch、pytestconfig、record_property、record_testsuite_property、record_xml_attribute、recwarn、tmp_path、tmp_path_factory、tmpdir、tmpdir_factory 使用 'pytest --fixtures [testpath]' 获取帮助。
最后一组数据应该无法通过。 (这是故意的)
【问题讨论】: