Search code examples
pytestfixtures

Use multiple parameters yielded by a request fixture in pytest


how can I yield multiple parameters in a request fixture and use these as arguments in a test function? Below is a sample code of the request fixture

@pytest.fixture(params=range(ITERNUM))
def data(request):
    yield request.param

def test_01(data):
    print(data)

I would like to have custom Ids for each data e.g. current output of the test name is data[01]. I would like to output more customized test ID e.g. 'test-name[value_of_data]'

It would be similar approach as that explained here but the test id string should be created dynamically for each value of data.

Is it possible?

Thanks, Archie


Solution

  • Resolved it by passing a callable to the ids parameter of the fixture.