【pytest】失敗用例重跑
阿新 • • 發佈:2022-03-04
一. 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