ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Pytest(4)失败重跑插件pytest-rerunfailures

2021-04-27 18:55:05  阅读:317  来源: 互联网

标签:插件 test2 py rerunfailures pytest reruns test example


安装:

pip3 install pytest-rerunfailures
 

重新运行所有失败用例

要重新运行所有测试失败的用例,请使用--reruns命令行选项,并指定要运行测试的最大次数:

$ pytest --reruns 5

 

添加重新运行的延时

要在两次重试之间添加延迟时间,请使用--reruns-delay命令行选项,其中包含您希望在下一次测试重试开始之前等待的秒数:

$ pytest --reruns 5 --reruns-delay 1

 

重新运行指定的测试用例

要将个别测试用例标记为不稳定,并让它们在失败时自动重新运行,添加flaky标记与您希望测试运行的最大次数:

@pytest.mark.flaky(reruns=5)
def test_example():
    print(1/0)

执行结果

test2.py::test_example RERUN                                             [100%]
test2.py::test_example RERUN                                             [100%]
test2.py::test_example RERUN                                             [100%]
test2.py::test_example RERUN                                             [100%]
test2.py::test_example RERUN                                             [100%]
test2.py::test_example FAILED                                            [100%]
test2.py:26 (test_example)
@pytest.mark.flaky(reruns=5)
    def test_example():
>       print(1/0)
E       ZeroDivisionError: division by zero

test2.py:29: ZeroDivisionError

 

同样的,这个也可以指定重新运行的等待时间

@pytest.mark.flaky(reruns=5, reruns_delay=1)
def test_example():
    print(1/0)

 

输出示例

这是使用--reruns 2-r aR运行时插件提供的输出示例

 test2.py ⨯                                                                                                                                                                                              100% ██████████
=============================================================================================== rerun test summary info ================================================================================================
RERUN test2.py::test_example
RERUN test2.py::test_example
=============================================================================================== short test summary info ================================================================================================
FAILED test2.py::test_example - ZeroDivisionError: division by zero

Results (0.14s):
       1 failed
         - test2.py:28 test_example
       2 rerun

 

注意事项

如果指定了用例的重新运行次数,则在命令行添加--reruns对这些用例是不会生效的
 

兼容性

  • 这个插件可能与类,模块和封装级夹具一起使用。
  • 该插件与pytest-xdist的–looponfail标志兼容。
  • 该插件与核心–pdb标志兼容

标签:插件,test2,py,rerunfailures,pytest,reruns,test,example
来源: https://blog.51cto.com/u_15183212/2737517

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有