背景:unittest+HTMLTestRunner是之前了解到的主流Python自动化测试框架,最近接触到pytest框架,发现貌似各方面都超越unittest,是一个很成熟的全功能的测试框架.于是学习并记录下来.
安装:

验证版本:

用例基本规则:
pytest是基于unittest的扩展框架,比unittest更简洁,更高效,而且能够兼容unittest。使用pytest编写用例,需要遵守以下规则:
(1)测试文件名必须以“test_”开头或者"test"结尾(如:test_ab.py)
(2)测试方法必须以“test”开头。
(3)测试类命名以"Test"开头。
pytest会在当前的目录下,寻找以test开头的文件(即测试文件),找到测试文件之后,进入到测试文件中寻找test_开头的测试函数并执行

执行:

网友评论