mardi 30 avril 2019

pytest test parameterization override

I am currently parametrizing all of my testcases using pytest_generate_tests and this works well.

What I'd like to do now is override this behavior for a specific test. If I try and use the pytest.mark.parametrize decorator on the test itself, I get a ValueError: duplicate error which is understandable as I'm now trying to parametrize the test in two places.

Is there a way I can override the "default" parameterization for this one test case?

I can achieve this by doing something like the below but its a very hacky way to do it:

def pytest_generate_tests(metafunc):
    fixture_modes = ['mode1', 'mode2']
    if 'fixture' in metafunc.fixturenames:
        fixture  = metafunc.config.getoption('fixture')
        if fixture:
            fixture_modes = [fixture]
        if metafunc.function.__name__ != 'func_to_skip':
            metafunc.parametrize('fixture_mode', fixture_modes, indirect=True)

Is there a better way to do this?

Aucun commentaire:

Enregistrer un commentaire