参数化数据 @pytest.mark.parametrize("参数名",列表数据)

作用与unittest中的ddt一样,测试用例中传入测试数据

在测试用例的前面加上:

@pytest.mark.parametrize("参数名",列表数据)

参数名:用来接收每一项数据,并作为测试用例的参数传入

列表数据:一组测试数据。

import pytest
class Test_A:
cases=[{'title':1,'id':2},{'title':3,'id':4}]

@pytest.fixture(scope='class')
def c(self):
print('ccc')
yield
print('ggg')

@pytest.mark.parametrize('case',cases)
def test_b(self,c,case):
print('bbb')
print('参数分别是:{}'.format(case))
print('title值是{}'.format(case['title']))

猜你喜欢

转载自www.cnblogs.com/yzwdcjs/p/12560717.html