I want exhaustively test function by calling it with all possible argument combinations:
@pytest.mark.parametrize("a", [1, 2])
@pytest.mark.parametrize("b", [1, 2, 3, 4])
@pytest.mark.parametrize("c", [1, 2, 3])
@pytest.mark.parametrize("d", [1, 2])
def test_func_variations(a, b, c, d):
assert func(a, b, c, d) == a*b*c+d
Though some of these combinations don't make sense. Is there an easy way to skip these combinations with py.test, e.g. too have logic like this:
def test_func_variations(a, b, c, d):
if (a == 1 and b in (2, 3)) or (a == 2 and c == 3):
skip_me()
assert func(a, b, c, d) == a*b*c+d
Okay, that was easy:
@pytest.mark.parametrize("a", [1, 2])
@pytest.mark.parametrize("b", [1, 2, 3, 4])
@pytest.mark.parametrize("c", [1, 2, 3])
@pytest.mark.parametrize("d", [1, 2])
def test_func_variations(a, b, c, d):
if (a == 1 and b in (2, 3)) or (a == 2 and c == 3):
pytest.skip("invalid parameter combination")
assert func(a, b, c, d) == a*b*c+d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With