我有一个参数化的Pytest测试,例如:
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
问题是,如何使用@ pytest.mark.skipif跳过ID为“ 0001”的测试?
答案 0 :(得分:2)
您可以使用pytest.param(reference)来接受marks
可选参数:
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
您也可以(这是一种很好的做法)指出为什么跳过测试:
pytest.param(MyDB(id="0001", result=True),
marks=pytest.mark.skip(reason=('a good and informative reason'))