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
我不知道为什么会有“间接固定装置”,知道吗? 我使用的是Python3.7和Windows1064位
对于出于与我相同的原因来到这里的任何其他人,如果您使用ID列表标记测试,则ID列表必须是一个名为的参数,如下所示:
而不是
TL;DR-
问题出在线路上
应将其写入逗号分隔的字符串:
您获得了
indirect fixture
,因为pytest无法解压缩给定的argvalues
,因为它获得了错误的argnames
参数。您需要确保所有参数都作为一个字符串写入请参阅documentation:
也就是说,您应该将要参数化的参数编写为单个字符串,并使用逗号分隔它们。因此,您的测试应该如下所示:
由于省略了参数值周围的方括号,我得到了类似的错误,例如
给出错误“间接夹具“p”不存在”。修复方法:
相关问题 更多 >
编程相关推荐