有招 - 你的生活妙招指南_妙招网
标题:
python接口自动化-pytest-重试测试
[打印本页]
作者:
小震
时间:
2024-12-30 10:37
标题:
python接口自动化-pytest-重试测试
背景
编写自动化过程中,经常会遇到服务不稳定情况,只执行一次结果可能说明不了问题,这个时候引入重试机制,能大幅提高用例成功率,但是也会增加执行时间。
一、用法
1、安装
pip install pytest-rerunfailures
2、装饰器用法
@pytest.mark.flaky(reruns=2, reruns_delay=5)
-代表重试2次,每次间隔5s
3、命令行用法:
命令:pytest --reruns 重试次数 --reruns-delay 重试间隔
比如:pytest --reruns 2 --reruns-delay 5
(表示:运行失败的用例可以重新运行2次,第一次和第二次的间隔时间为5秒钟)
二、实战
1、装饰器用法
-装饰器-作用域-function
[attach]291[/attach]
-装饰器-作用域-class
2、命令行用法
命令行-作用域-session
pytest test_case/api/ --reruns 2 --reruns-delay 5
命令行-作用域-module
pytest test_case/api/xxx.py --reruns 2 --reruns-delay 5
命令行-作用域-class
pytest test_case/api/xxx.py::xx类 --reruns 2 --reruns-delay 5
命令行-作用域-function
pytest test_case/api/xxx.py::xx类::xx方法 --reruns 2 --reruns-delay 5
欢迎光临 有招 - 你的生活妙招指南_妙招网 (https://www.yoozhao.com/)
Powered by Discuz! X3.5