本文的前提是你已经了解了 pytest 的 ‘fixture’ ,不熟悉的朋友可以移步 > 传送门
pytest 提供了强大的 fixture 功能,当 fixture 的 params 参数为 list 时,会执行 ‘list参数长度’ 次测试
import pytest
is_a = [1, 2, 3, 4, 5, 6, 11, 12]
@pytest.fixture(params=is_a)
def is_a(request):
print(request)
return request.param
def test_a(is_a):
assert is_a < 10
执行结果为:
(venv) admindeMBP:My_Function_Test admin$ pytest
============================================================================================