Pytest 设置跳过、预期失败用例

例子:

 @pytest.mark.skip

跳过该case

@pytest.mark.skip(reason="代码无实现")
@pytest.mark.add
def test_add_02():
    assert (2+2) == 3

@pytest.mark.skipif

如果满足sys.platform == 'win',则跳过

@pytest.mark.skipif(sys.platform == 'win',reason="cannot run on windows")
def test_case_01():
    assert True

pytest.skip(reason)

代码层面跳过,如果没执行过login(),则跳过

def login():
    print("login")
    return True

def test_func():
    if not login():
        pytest.skip("Not login!")
    print("end")
posted @ 2022-05-08 17:02  lms21  阅读(77)  评论(0)    收藏  举报