断言,自动判断接口返回的结果与预期结果是否一致 from common.get_mysql import * def test_assert(): a=0 b=1 # assert a,'断言失败打印的信息' # 自定义断言失败打印的信息,用逗号隔开 assert not a,'断言失败打印的信息' assert b,'断言失败打印的信息' c='c' d='adacde' e='aeewd' assert c in d,'断言失败打印的信息' assert c not in e,'断言失败打印
Python assert(断言)可以分别后面的判断是否正确,如果错误会报错 示例: a = 1 assert type(a) is int print('No problem') 输出结果: No problem a = ' assert type(a) is int print('No problem') 输出结果: Traceback (most recent call last): File "D:/test.py", line 3, in <module>