def fatorial(n):
if n <= 1:
return 1
else:
return n*fatorial(n - 1)
import pytest
@pytest.mark.parametrize("entrada","esperado",[
(0,1),
(1,1),
(2,2),
(3,6),
(4,24),
(5,120)
])
def testa_fatorial(entrada,esperado):
assert fatorial(entrada) == esperado
错误:
ERROR collecting Fatorial_pytest.py ____________________________________________________________________
In testa_fatorial: indirect fixture '(0, 1)' doesn't exist
我不知道为什么我得到“间接夹具”。知道吗?我使用的是 python 3.7 和 windows 10 64 位。
原文由 Laurinda Souza 发布,翻译遵循 CC BY-SA 4.0 许可协议
长话短说——
问题出在线路上
它应该写成逗号分隔的字符串:
你得到了
indirect fixture
因为pytest无法解压给定的argvalues
因为它有一个错误的argnames
参数。您需要确保所有参数都写为一个字符串。请参阅 文档:
意思是,您应该将要参数化的参数写为单个字符串,并使用逗号分隔它们。因此,您的测试应如下所示: