实际使用场景中,如果有测试用例在某种情况下不需要执行或者是没写好的测试用例,就需要跳过,测试用例跳过有两种方法:
-
@pytest.mark.skip
import pytest @pytest.mark.skip(reason="不需要执行") def test_skip(): print("测试用例跳过")
-
@pytest.mark.skipif
可以加判断条件mobile = '1300000000' import pytest @pytest.mark.skipif('len(mobile) != 11') def test_skipif(): print("测试用例跳过")
-
pytest.skip()
在函数里判断跳过def test_skip(): mobile = '1300000000' if len(mobile) != 11: pytest.skip("skip") assert len(mobile) == 11