pytest失败重试插件pytest-rerunfailures

首先安装失败重试插件:

pip install pytest-rerunfailures

有三种方式来使用失败重试

第一种:在测试方法上使用@pytest.mark.flsky()装饰器

@pytest.mark.flaky(reruns=1) #失败重跑一次 @pytest.mark.flaky(reruns=1, reruns_delay=2) #失败重跑一次,在每次开跑前会等到2s

一个简单的例子如下:

#投资成功 @pytest.mark.flaky(reruns=1) def test_invest_success(self, common_driver): WelcomePage(common_driver).swipe_screen() WelcomePage(common_driver).click_experience_now() LoginPage(common_driver).click_register_login() LoginPage(common_driver).input_phone(login_success_data["phone"]) LoginPage(common_driver).input_pwd(login_success_data["pwd"]) IndexPage(common_driver).click_later() InvestPage(common_driver).enter_invest() before_invest_money = InvestPage(common_driver).get_user_left_money() InvestPage(common_driver).input_invest_money(invest_success_data["money"]) InvestPage(common_driver).invest_now() InvestPage(common_driver).click_confirm() InvestPage(common_driver).click_back() IndexPage(common_driver).click_me() after_invest_money = UserInfoPage(common_driver).get_user_left_money() assert float(before_invest_money) == float(after_invest_money) + invest_success_data["check"]

第二种:在命令行使用

pytest test_invest.py::TestInvest::test_invest_success --reruns 1 #失败重跑一次 pytest test_invest.py::TestInvest::test_invest_success --reruns 1 --reruns-delay 2 #失败重跑一次,在每次开跑前会等到2s

一个简单的例子如下:

第三种:在main.py中使用

#失败重跑一次 pytest.main([ "--reruns=1", "-m", "fail", "--junitxml", f"{test_reports}/autotest_report_{cur_time}.xml", "--html", f"{test_reports}/autotest_report_{cur_time}.html"] ) #失败重跑一次,在每次开跑前会等待2s pytest.main([ "--reruns=1", "--reruns-delay=2", "-m", "fail", "--junitxml", f"{test_reports}/autotest_report_{cur_time}.xml", "--html", f"{test_reports}/autotest_report_{cur_time}.html"] )

 


__EOF__

本文作者cnhkzyy
本文链接https://www.cnblogs.com/my_captain/p/12720190.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   cnhkzyy  阅读(1941)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示