我们平时测试某些功能点的时候,需要多次输入参数进行测试,比如登录(需要输入各种类型的数值),这些实际都是1条测试用例。
在使用postman、pytest等,就需要参数化。pytest的参数化工具是parametrize。
import pytest
def add(x):
return x + 2
class Test_Class_Add():
@pytest.mark.parametrize("input, result", [
(2, 5),
(13, 5),
(23, 25),
(23, 35)
])
def test_add1(self, input, result):
assert add(input) == result
测试结果: