Reputation: 195
I have a parametrized Pytest test such as:
testdata = [
MyDB(id="0001", result=True),
MyDB(id="0002", result=False)
]
@pytest.mark.parametrize("data", testdata, ids=[repr(id) for id in testdata])
def test_1(data):
pass
The question is, how can I use @pytest.mark.skipif to skip the test with id "0001"?
Upvotes: 2
Views: 314
Reputation: 6209
You could use pytest.param (reference) which accepts a marks
optional argument:
testdata = [
pytest.param(MyDB(id="0001", result=True), marks=pytest.mark.skip)
MyDB(id="0002", result=False)
]
@pytest.mark.parametrize("data", testdata, ids=[repr(id) for id in testdata])
def test_1(data):
pass
You also can (and it is a good practice) indicate why the test is skipped:
pytest.param(MyDB(id="0001", result=True),
marks=pytest.mark.skip(reason=('a good and informative reason'))
Upvotes: 3