1.指定测试用例
(1)指定路径 pytest.main([“testcase/test_case.py::TestOrder::test_order”])
(2)-m 运行指定标记的用例 pytest -m “smoke or order” 或 pytest.main([“-m”, “smoke or order”])
(3)-k 运行匹配指定字符串的测试用例 匹配包名、模块、类、函数、方法
pytest -k order testcase/test_case.py::TestOrder
或
pytest.main([“-k”, “order”, “testcase/test_case.py::TestOrder”])
2.控制执行过程
(1)用例失败重新执行次数 --rerun
需要按照包pytest-refailures
# 运行失败后该用例重新运行最多3次
pytest.main(["--reruns", "3", "testcase/test_case.py"])
# 命令行形式
pytest --reruns=3 testcase/test_case.py
(2)用例执行失败停止运行
-
遇到用例失败就停止项目运行 -x 或者–exitfirst
-
失败几个用例后停止项目运行 --maxfail=num
(3)运行上次失败案例
– if或–last-failed 只执行上次运行失败的用例
–ff或 --failed-first 先执行失败的,再执行项目中其他的
3.执行结果展示
(1) -s 测试结果里显示print里的信息(默认不显示的)
(2) -v 查看详细报告/测试结果
(3) -q 简略执行
pytest.ini
pytest.ini能做什么
1、修改用例的命名规则
2、配置日志格式,比代码配置更方便——日志分为输出到控制台的和保存到文件中的
3、添加标签,防止运行过程中报告警错误
4、指定执行目录
5、配置pytest命令运行所带参数