蟑螂恶霸的博客 蟑螂恶霸的博客
首页
  • Web自动化
  • 自动化测试框架
  • 接口自动化
  • 测试面试题
  • 技术文档
  • GitHub技巧
  • 博客搭建
  • Vue
  • JavaScript
  • Nginx
  • 自动化测试
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

蟑螂恶霸

一个爱折腾的程序员,什么都想试试!
首页
  • Web自动化
  • 自动化测试框架
  • 接口自动化
  • 测试面试题
  • 技术文档
  • GitHub技巧
  • 博客搭建
  • Vue
  • JavaScript
  • Nginx
  • 自动化测试
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • web自动化

  • 自动化测试框架

  • 接口自动化测试

  • 测试面试题

  • Pytest

    • 快速入门和基础讲解
    • assert断言详细使用
    • setup和teardown的详细使用
    • fixture的详细使用
    • 测试用例执行后的几种状态
    • conftest.py的详细讲解
    • skip、skipif跳过用例
    • 使用自定义标记mark
    • 参数化@pytest.mark.parametrize
    • fixture 传参数 request的详细使用
    • 失败重跑插件pytest-rerunfailures的详细使用
      • 环境前提
      • 安装插件
      • 提前了解重点
      • 重新运行所有失败的用例
        • 知识点
        • 添加重新运行的延时
      • 重新运行指定的测试用例
        • 小栗子
        • 执行结果
        • 同样的,这个也可以指定重新运行的等待时间
        • 注意事项
      • 兼容性问题
    • 测试结果生成HTML报告插件之pytest-html的详细使用
    • 重复执行用例插件之pytest-repeat的详细使用
    • 配置文件pytest.ini的详细使用
    • 多重校验插件之pytest-assume的详细使用
    • 分布式测试插件之pytest-xdist的详细使用
    • pytest-xdist分布式测试的原理和流程
    • 超美测试报告插件之allure-pytest的基础使用
    • 我们需要掌握的allure特性
    • allure的特性,@allure.step()、allure.attach的详细使用
    • allure的特性,@allure.description()、@allure.title()的详细使用
    • allure的特性,@allure.link()、@allure.issue()、@allure.testcase()的详细使用
    • allure 打标记之 @allure.epic()、@allure.feature()、@allure.story() 的详细使用
    • allure 环境准备
    • allure.severity 标记用例级别
    • 清空 allure 历史报告记录
    • allure 命令行参数
    • 参数化 parametrize + @allure.title() 动态生成标题
    • 详解 allure.dynamic 动态生成功能
    • 使用 pytest-xdist 分布式插件,如何保证 scope=session 的 fixture 在多进程运行情况下仍然能只运行一次
  • 自动化测试
  • Pytest
蟑螂恶霸
2022-07-22
目录

失败重跑插件pytest-rerunfailures的详细使用

# 环境前提

以下先决条件才能使用pytest-rerunfailures

  • Python 3.5, 最高 3.8, or PyPy3
  • pytest 5.0或更高版本

# 安装插件

pip3 install pytest-rerunfailures -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
1

# 提前了解重点

命令行参数:--reruns n(重新运行次数),--reruns-delay m(等待运行秒数)

**装饰器参数:**reruns=n(重新运行次数),reruns_delay=m(等待运行秒数)

# 重新运行所有失败的用例

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

pytest --reruns 5 -s 
1

# 知识点

运行失败的 fixture 或 setup_class 也将重新执行

# 添加重新运行的延时

要在两次重试之间增加延迟时间,使用 --reruns-delay 命令行选项,指定下次测试重新开始之前等待的秒数

pytest --reruns 5 --reruns-delay 10 -s
1

# 重新运行指定的测试用例

要将单个测试用例添加flaky装饰器 @pytest.mark.flaky(reruns=5) ,并在测试失败时自动重新运行,需要指定最大重新运行的次数

# 小栗子

import pytest


@pytest.mark.flaky(reruns=5)
def test_example():
    import random
    assert random.choice([True, False, False])
1
2
3
4
5
6
7

# 执行结果

collecting ... collected 1 item

11_reruns.py::test_example RERUN                                         [100%]
11_reruns.py::test_example PASSED                                        [100%]

========================= 1 passed, 1 rerun in 0.05s ==========================
1
2
3
4
5
6

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

@pytest.mark.flaky(reruns=5, reruns_delay=2)
def test_example():
    import random
    assert random.choice([True, False, False])
1
2
3
4

# 注意事项

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

# 兼容性问题

  • 不可以和fixture装饰器一起使用: @pytest.fixture()
  • 该插件与pytest-xdist的 --looponfail 标志不兼容
  • 该插件与核心--pdb标志不兼容

本文转自 https://www.cnblogs.com/poloyy/p/12687308.html (opens new window),如有侵权,请联系删除。

上次更新: 2022/10/15, 15:19:25
fixture 传参数 request的详细使用
测试结果生成HTML报告插件之pytest-html的详细使用

← fixture 传参数 request的详细使用 测试结果生成HTML报告插件之pytest-html的详细使用→

最近更新
01
实现定时任务数据库配置
06-09
02
SQL Server连接
02-22
03
RSA加密工具类
02-22
更多文章>
Theme by Vdoing | Copyright © 2022-2023 蟑螂恶霸 | Blog
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式