蟑螂恶霸的博客 蟑螂恶霸的博客
首页
  • 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 历史报告记录
      • 背景
        • 目录结构
        • 指定测试用例文件名称的栗子
        • 分开运行测试用例文件的栗子
      • --clean-alluredir 参数
    • allure 命令行参数
    • 参数化 parametrize + @allure.title() 动态生成标题
    • 详解 allure.dynamic 动态生成功能
    • 使用 pytest-xdist 分布式插件,如何保证 scope=session 的 fixture 在多进程运行情况下仍然能只运行一次
  • 自动化测试
  • Pytest
蟑螂恶霸
2022-07-22
目录

清空 allure 历史报告记录

# 背景

  • pytest 运行 测试用例生成 allure 报告时,当测试用例名称修改后重新运行,会保留历史运行记录
  • 又或者分开运行两个测试用例文件,但是 allure 报告生成目录是同一个,那么 allure 报告会同时显示两个文件的测试用例运行情况
  • 咱们来看看这种情况

# 目录结构

下面两个栗子都是这个目录结构

# 指定测试用例文件名称的栗子

# test_1.py 的代码

def test_1():
    print("test_1 文件的测试用例1")

def test_2():
    print("test_1 文件的测试用例2")
1
2
3
4
5

# 运行命令

进入该目录下,cmd 运行

pytest test_1.py --alluredir=./allure
1

# allure 报告

只有两条用例

# 修改后的 test_1.py 的代码

def test_11():
    print("test_1 文件的测试用例1")

def test_22():
    print("test_1 文件的测试用例2")
1
2
3
4
5

# 再次运行命令,查看 allure 报告

四条用例,包含了历史的两条,这不是我们希望看到的

# 分开运行测试用例文件的栗子

# test_2.py 的代码

def test_1():
    print("test_1 文件的测试用例1")

def test_2():
    print("test_1 文件的测试用例2")
1
2
3
4
5

# 分开运行 test_1 和 test_2 两个测试用例文件

# 先运行第一个
pytest test_1.py --alluredir=./allure

# 再运行第二个,此时应该希望 allure 报告只有 test_2.py 的测试用例
pytest test_2.py --alluredir=./allure
1
2
3
4
5

# 查看 allure 报告

出现了 test_1.py 的测试用例,这不是想要的结果

# --clean-alluredir 参数

# 前言

  • pytest 提供了 --clean-alluredir 参数可以清空 allure 报告生成的目录
  • 可以看看 pytest 的说明文档
pytest -h
1

# 将上面的栗子重新运行

# 先运行第一个
pytest test_1.py --alluredir=./allure

# 再运行第二个,此时应该希望 allure 报告只有 test_2.py 的测试用例
pytest test_2.py --alluredir=./allure --clean-alluredir
1
2
3
4
5

# 运行结果

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

上次更新: 2022/10/15, 15:19:25
allure.severity 标记用例级别
allure 命令行参数

← allure.severity 标记用例级别 allure 命令行参数→

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