I'm using pytest for unittests and I would like to parametrize the tests. I know I can use @pytest.mark.parametrize at class level and at method level.
@pytest.mark.parametrize("param1", [1,2,3,4,5])
class TestXYZ:
@pytest.mark.parametrize("param2", [6,7,8,9])
def test_xyz(self, param1, param2):
assert param1 == param2
However, in my case it happens that the param2 list depends on the actual param1 value. I would like to obtain sth like this:
@pytest.mark.parametrize("param1", [1,2,3,4,5])
class TestXYZ:
@pytest.mark.parametrize("param2", getparams(param1))
def test_xyz(self, param1, param2):
assert param1 == param2
However, i could not figure out how to do it.
I tried to use nested functions, but this did'nt work out, too:
@pytest.mark.parametrize("param1", [1,2,3,4,5])
class TestXYZ:
def test_gen(self, param1):
@pytest.mark.parametrize("param2", [6,7,8,9])
def test_xyz(self, param1, param2):
assert param1 == param2
return test_gen
Pytest then just collect a testcase for param1.