自动化测试框架的作用
1、提高测试效率,降低维护成本
2、减少人工干预,提高测试准确性,增加代码的重用性
pytest命名规则
1、模块名必须以test_开头或者以_test结束
2、测试类必须以Test开头,并且不能有init方法
3、测试方法必须以test开头
pytest的运行模式
1、主函数模式
1)运行所有:pytest.main()
2)运行指定模块:pytest.main(['-sv','test_login.py'])
3) 运行指定目录:pytest.main(['-sv','./testcase'])
2、命令行模式
1)运行所有:pytest
2)运行指定模块:pytest test_login.py
3)运行指定目录:pytest ./testcase
参数详解:
- -s:输出调试信息,包括print打印的信息
- -v: 打印用例执行的详细过程
- -q: 只显示整体测试结果
- -n: 支持多线程或分布式运行测试用例
pytest.main(['-sv','test_login.py','-n=2'])
pytest test_login.py -n 2
- -x: 第一个错误或测试失败时立即退出
- --reruns:失败了重新执行
pytest.main(['-sv','test_login.py','--reruns=2'])
pytest test_login.py --reruns 2
--html ./report/report.html 生成html报告