pytest重试_pytest不是内部或外部命令
pytest 内部 不是 重试 外部命令
2023-06-13 09:12:44 时间
大家好,又见面了,我是你们的朋友全栈君。
安装:
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标志不兼容
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/166276.html原文链接:https://javaforall.cn
相关文章
- pytest运行_ios怎么清理应用缓存在哪里
- pytest 执行用例_测试用例执行结果有哪些
- pytest报错_git是什么
- Pytest(6)重复运行用例pytest-repeat[通俗易懂]
- pytest指定用例_pytest执行多个py文件
- 用Pytest+Allure生成漂亮的HTML图形化测试报告[通俗易懂]
- 接口自动化测试之pytest用例管理框架2
- 接口自动化测试之pytest用例管理框架3
- pytest + yaml 框架 -5.调用内置方法和自定义函数
- pytest学习和使用2-初步使用和用例运行
- 软件测试|Pytest的必会技巧(一)
- ChatGPT帮我写Python + pytest + selenium框架