【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