1、主函数的方式
1
2if __name__ == '__main__': pytest.main("-s testapi.py")
注:-s是输出调试信息;testapi.py是运行的py文件
pytest.main(['-vs','--html=report.html','--reruns'...])——
右键-run 运行
2、命令行方式
Terminal执行命令:
运行testcase文件夹下的testapi.py文件。输入更加详细的运行信息(-v)和调试信息(-s)
补充:
-v 输出更加详细的运行信息
-s 输出调试信息
-n 多线程运行(pytest -n=2 ./testcase/testapi.py)
--reruns 数字 失败用例重跑(pytest --reruns=2 ./testcase/testapi.py 表示用例失败后重跑两次)
-x 出现一个用例失败则停止测试(pytest -x ./testcase/testapi.py )
--maxfail 出现几个失败才终止测试(pytest --maxfail=2 ./testcase/testapi.py 表示出现两个用例失败停止测试)
--html 报告的路径(pytest --html=./report.html ./testcase/testapi.py) 输出测试报告
总:pytest -vs -n=2 --reruns=2 --html=./report.html ./testcase/testapi.py
3、pytest.ini的配置文件来配置运行
①项目根路径下新建配置文件“pytest.ini”
②在新建配置文件里填写配置信息
测试用例main函数:
1
2if __name__ == '__main__': pytest.main("")
pytest.ini文件 :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15[pytest] # 配置命令,命令行参数 addopts= -vs -m"smoke" #测试用例的路径 testpaths=./testcase 默认规则,测试用例的文件默认以test开头 python_files = test_*.py #默认规则,测试用例的类默认以Test开头 python_classes = Test*.py #默认规则,测试用例的方法默认以Test*_开头 python_functions = test* #标记 (执行时 addopts添加-m"smoke") markers= smoke:maoyan
main函数右键run运行
最后
以上就是深情项链最近收集整理的关于pytest运行方式的全部内容,更多相关pytest运行方式内容请搜索靠谱客的其他文章。
发表评论 取消回复