pytest重运行失败用例
python版本必须3.5以上;pytest版本必须是5.0以上,不然会出现一些乱七八糟的问题,这也是官方建议。
安装 pytest-rerunfailures
pip install pytest-rerunfailures
重运行是指运行失败了,间隔几秒后再去运行,延迟时间可指定,次数也可指定 。
F:\git\AuomationTest\TestPytest\code\ch1>pytest --reruns 5
================================================================================ test session starts ================================================================================
platform win32 -- Python 3.7.7, pytest-6.2.0, py-1.9.0, pluggy-0.13.1
plugins: allure-pytest-2.8.24, cov-2.8.1, emoji-0.2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, rerunfailures-9.1.1, xdist-2.1.0
collected 6 items
test_one.py . [ 16%]
test_two.py RRRRRF [ 33%]
tasks\test_four.py .RRRRRF [ 66%]
tasks\test_three.py .. [100%]
================================================================= 2 failed, 4 passed, 1 warning, 10 rerun in 0.13s ==================================================================
我输入的命令:pytest –reruns 5
// reruns 指的就是重运行的的次数用例运行失败了后,就会再运行5次
图片上的黄色大写R就是重运行的标识,可以看出运行失败的又运行了5次 。
–
接
下来
我们继续 …
F:\git\AuomationTest\TestPytest\code\ch1>pytest --reruns 5 --reruns-delay 5
================================================================================ test session starts ================================================================================
platform win32 -- Python 3.7.7, pytest-6.2.0, py-1.9.0, pluggy-0.13.1
plugins: allure-pytest-2.8.24, cov-2.8.1, emoji-0.2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, rerunfailures-9.1.1, xdist-2.1.0
collected 6 items
test_one.py . [ 16%]
test_two.py RRRRRF [ 33%]
tasks\test_four.py .RRRRRF [ 66%]
tasks\test_three.py .. [100%]
================================================================= 2 failed, 4 passed, 1 warning, 10 rerun in 50.16s =================================================================
是不是觉得和上面的图片显示的一样呀,虽然显示的是一样,但是在运行期间是不一样的 。
这次输入的命令: pytest –reruns 5 –reruns-delay 5
// –reruns-delay 5 是指延迟5秒重运行一次,重运行5次
当然我们也可以指定相应错误重运行
// 只针对断言错误的重运行 5 次
pytest –reruns 5 –only-rerun AssertionError// 只针对断言错误或值错误的重运行 5 次
pytest –reruns 5 –only-rerun AssertionError –only-rerun ValueError重运行单个用例
import pytest
@pytest.mark.flaky(reruns=5)
def test_passing():
assert (1, 2, 3) == (1, 2, 3)
@pytest.mark.flaky(reruns=5, reruns_delay=2)
def test_failing():
assert (1, 2, 3) == (3, 2, 1)
小小总结可能会解决你的问题,也可能解决不了你的问题,但还是希望对您有所帮助,感谢阅读,如有疑义,欢迎来扰!未完待续…
一直都在努力变好中,希望您也是,加油!
Original: https://blog.csdn.net/LIFENG0402/article/details/112686218
Author: 番茄牛腩不吃番茄
Title: pytest重运行失败用例
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/775080/
转载文章受原作者版权保护。转载请注明原作者出处!