我尝试学习根据参数自动生成测试用例ID的方法。我有以下基于在线研究的代码,但实际上我真正想要的id只能是参数的特有
< Function "test_xxx['life': 2]" >
< Function "test_xxx['life': 4]" >
< Function "test_xxx['life': 5]" >
我该怎么做?
#code I have tried
def ids_func(param):
return repr(param)
@pytest.fixture(scope='function')
def setup1(self, request):
return f'{request.param["name"]} in {request.param["state"]}'
@pytest.fixture(scope='function')
def setup2(self, request):
return f'{request.param["life"]} years'
@pytest.mark.parametrize('setup1, setup2',
[(dict(name='name1', state='NY'), dict(life=2)),
(dict(name='name2', state='NJ'), dict(life=4)),
(dict(name='name3', state='CA'), dict(life=5)),
(dict(name='name0', state='MA'), dict(life=8))],
ids=ids_func,
indirect=['setup1', 'setup2'])
def test_xxx(self, setup1, setup2):
pass