pytest fixture 参数化

@pytest.fixture有一个params参数,接受一个列表,列表中每个数据都可以作为用例的输入。也就说有多少数据,就会形成多少用例。
如下面例子,就形成3条用例
test_parametrizing.py
 1 import pytest
 2 
 3 seq=["case1","case2","case3"]
 4 
 5 
 6 @pytest.fixture(scope="module",params=seq)
 7 def params(request):
 8     return request.param
 9 
10 
11 
12 def test_params(params):
13     print(params)
14     assert "case" in params

执行命令:

pytest -rA  test_parametrizing.py

执行结果:

猜你喜欢

转载自www.cnblogs.com/moonpool/p/11351859.html