【pytest】失败用例重跑

一. pytest内部机制

    pytest自带失败重跑机制,在运行中传入参数即可。

    --lf 参数:运行上次失败的用例,如果没有则全部运行。

    --ff参数:运行全部用例,上次失败的优先运行。

  --lf, --last-failed   rerun only the tests that failed at the last run (or all if none failed)
  --ff, --failed-first  run all tests, but run the last failures first.

 

二. 使用pytest-rerunfailures

1、安装

pip install pytest-rerunfailures

2、针对单个测试类或者测试用例

@pytest.mark.flaky(reruns=1, reruns_delay=3)

  reruns=1,   重跑次数

  reruns_delay=3   每次间隔

 

3. 全局使用

pytest --reruns 2 --reruns-delay 5 -s  [dir or case file or case class or case method]

 

4. 在pytest.ini定义

addopts= -vs --reruns=9 --reruns-delay=3

 

 

参考链接:

https://www.cnblogs.com/huny/p/13512377.html

https://www.cnblogs.com/crdym/p/14967837.html

https://docs.pytest.org/en/7.0.x/search.html?q=rerun

posted @   代码诠释的世界  阅读(874)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示