Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

py.test skip depending on parameters

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
like image 606
DikobrAz Avatar asked Aug 31 '25 22:08

DikobrAz


1 Answers

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
like image 166
DikobrAz Avatar answered Sep 03 '25 15:09

DikobrAz