pytest.exit()方法

测试过程中,常常需要在session级别的setup中校验数据是否正确,若不正确,则需要直接停止当前测试用例后续的运行

此时,可使用pytest.exit()方法

源码:

 

msg: 退出测试进程时显示的信息。
returncode: 当退出pytest时返回的一个状态码,为 int 类型。

使用:

def test_first():
    print("first")

def test_second():
    print("second")
    pytest.exit("退出测试")

def test_third():
    print("third")

此时,运行时,只会打印first和second。然后则会直接退出测试,不打印third

posted @ 2022-12-12 11:32  只为。  阅读(480)  评论(0)    收藏  举报