Pytest 单元测试框架之断言
1、Pytest 中断言只能通过 assert 断言
- 断言为真 True
- 断言为假 False / not True
- 断言包含 a in b
- 断言相等 a == b
- 断言不等 a != b
import pytest def test_true(): assert True def test_false01(): assert not True def test_false02(): assert False def test_in(): res = '{"username":"python"}' assert "python" in res def test_equal(): assert 1 == 1 def test_not_equal(): assert 1 != 2 if __name__ == '__main__': pytest.main(["-sv","test_demo2.py"]) # 结果如下 test_demo2.py::test_true PASSED test_demo2.py::test_false01 FAILED test_demo2.py::test_false02 FAILED test_demo2.py::test_in PASSED test_demo2.py::test_equal PASSED test_demo2.py::test_not_equal PASSED
作者:一个老宅男
微信:ZhengYing8887
出处:https://www.cnblogs.com/ZhengYing0813/
备注:本文版权归作者所有,欢迎转载和添加作者微信探讨技术,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。