Я пытаюсь научиться автоматически генерировать идентификатор тестового случая на основе параметра. У меня есть следующий код, основанный на исследованиях онлайн, но на самом деле то, что мне действительно нравится 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