pytest是python第三方单元测试框架。
它本身功能非常强大,而且提供丰富的扩展。目前得到广泛的应用。
Github: https://github.com/pytest-dev/pytestpip
安装: >pip install pytest
文档: https://docs.pytest.org/en/latest/
pytest和unittest语法类似
# 1、测试文件名必须以 test 开头# 2、测试函数 必须以 test 开头# 3、测试类 必须以 Test 开头# 4、测试方法 必须以 test 开头import pytestdef add(a, b):return a + bdef test_add1():c = add(1, 2)assert c == 3def test_add2():c = add(1.1, 2.2)assert c == 3.3class TestAdd:def test_add3(self):c = add(1.5, 2.5)assert c == 4if __name__ == '__main__':pytest.main(["-vs", "./"]) # -vs 参数会打印更详细的信息 ,参数2:要运行哪些文件 ./为当前目录下的所有test*.py

