如何重新运行失败的测试并为 python3 py.test 设置重试 [英] How to re-run Failed Test and set re-tries for python3 py.test

查看:46
本文介绍了如何重新运行失败的测试并为 python3 py.test 设置重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎没有发送 http 请求的 Web 服务相关测试,响应由 py.test 测试用例验证.我通常会在 50 次测试中遇到 1 或 2 次失败,这些失败是由于网络服务器响应收集间歇性缓慢或网络造成的.

I have few web service related test which sends http requests and the response is verified by py.test test cases. I usually get 1 or 2 failures out of 50 tests which are fails due to intermittent slow web server response gathering or due to network.

在将 py.test 测试用例实际标记为失败测试用例之前,有没有一种方法可以重新运行它或将其添加到退休次数?像运行测试 3 次,然后将其标记为失败并转到下一个,如果测试通过任何尝试(1 次或 2 次或 3 次),则将其标记为通过?

Is there a way I can re-run or add number of retires to a py.test test case before actually marking it as a Failed one ? Something like run a test 3 times before marking it as failure and moving to the next one, If test passes in any attempt(1 or 2 or in 3) mark it as passed ?

推荐答案

flaky 描述了一个可能的解决方案:https://github.com/box/flaky-- 默认情况下允许重新运行失败的测试一次,或最多 n 次.

flaky describes a possible solution to your problem: https://github.com/box/flaky -- It allows for re-running failed tests once as a default, or up to n times.

您也可以尝试使用 Looponfail:https://pytest.org/latest/xdist.html.虽然它在技术上意味着允许更改与失败测试相关的文件,但它仍会在失败后暂停您正在运行的测试.

You could also try using Looponfail: https://pytest.org/latest/xdist.html. Although it's technically meant to allow for altering a file associated with the failed test, it'll still pause the test you're running after a failure.

希望这会有所帮助.

这篇关于如何重新运行失败的测试并为 python3 py.test 设置重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆