Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the parameter ID in a pytest fixture?

Is it possible to get the parameter ID in a Pytest fixture?

import pytest

@pytest.fixture(
     params = ['a', 'b', 'c'],
     ids    = ['x', 'y', 'z'])
def foo(request):
   myParam = request.param
   myID    = "How do I get the current ID?"
like image 761
ajwood Avatar asked Nov 10 '22 08:11

ajwood


1 Answers

One way to do it is passing the ID along as a parameter:

import pytest

params = ['a', 'b', 'c']
ids    = ['x', 'y', 'z']
@pytest.fixture(params=zip(params,ids), id=lambda x: x[1]):
def foo(request):
    myParam = request.param[0]
    myID    = request.param[1]

This is ugly, but it works.

like image 139
ajwood Avatar answered Jan 04 '23 01:01

ajwood