断言:
将实际结果与预期结果进行比对。
pytest 使用 python 标准 assert 进行断言,assert 格式:
assert expression [, arguments]
# expression 为 True 则 pass
# expression 为 False 则 抛出异常,有 argument 则输出 argument
'''
expression:
1)比较运算
2)逻辑运算 and | or | not
3)身份运算 is | is not
4)成员运算 in | not in
'''
示例:
# File : test_demo_13.py # IDE : PyCharm import pytest a = 4 b = [4, 5, 6] c = 4 d = 0 def test_1(): assert a <= c, '断言出错' def test_2(): assert a and d, '断言出错' def test_3(): assert a is c, '断言出错' def test_4(): assert a in b, '断言出错' if __name__ == '__main__': pytest.main(['-s', '-q', 'test_demo_13.py'])