失敗重跑需要依賴pytest-rerunfailures插件,使用pip安裝就行
pip install pytest-rerunfailures
用例失敗重跑的方法:
-
在用例上添加裝飾器@pytest.mark.flaky(reruns=2, reruns_delay=4) reruns為次數,reruns_delay間隔時間,單位s(對部分用例生效)
-
在pytest.ini文件中addopts = 添加參數–reruns n (n:為重試的次數)(對所有用例生效)
方法一:單個用例失敗重跑
方法二:所有用例失敗重跑