Skip to content Skip to sidebar Skip to footer

Provide Default Argument Value For Py.test Fixture Function

Is there a better way for me to provide default value for argument pytest.fixture function? I have a couple of testcases that requires to run fixture_func before testcase and I wo

Solution 1:

None is the default result

request.param.get('argA', None) 

So, you can just:

argA = request.param.get('argA', 'default value for argA')

Solution 2:

Add params to your fixture:

@pytest.fixture(scope='function', params=[{'arg1': 'default'}, {'arg2': 'default'}])
def my_fixture(request):
    return request.param['arg1'] + request.param['arg1']

Post a Comment for "Provide Default Argument Value For Py.test Fixture Function"