Pytest skip test with certain parameter value

Viewed 8200

I have tests that I want to parameterize, but there are certain tests that should only be applied to one value of the parameters. To give a specific example, below, I would like to apply parameters one and two to test_A, but only supply parameter one to test_B.

Current Code

@pytest.fixture(params=['one', 'two'])
def data(request):

    if request.param == 'one'
         data = 5
    return data

def test_A(data):

    assert True

def test_B(data):

    assert True

Desired Results

I basically want something that looks like this, but I can't figure out how to code this properly in pytest:

@pytest.fixture(params=['one', 'two'])
def data(request):

    data = 5
    return data

def test_A(data):

    assert True

@pytest.skipif(param=='two')
def test_B(data):

    assert True
2 Answers
Related