pytest用例失败重试

安装​​pytest-rerunfailures​​用例失败重跑插件

因为测试环境的网络环境不稳定,经常会导致测试用例失败,需要多运行几次用例,可以用rerunfailures插件来解决

# 安装pytest-rerunfailures
pip install pytest-rerunfailures

在pytest配置文件中配置对应的失败用例重试参数

addopts参数增加 --reruns 3
参数3表示用例失败后重跑次数

# [pytest]表示这是一个pytest配置文件
[pytest]
# addopts 表示执行pytest时加的参数,-s是输出打印,vvv是最详细显示, --alluredir= 测试报告目录
# pytest默认的报告参数是 --html=report/report.html
addopts = -s -vvv --reruns 3