• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Pytest学习笔记18-allure:清空测试报告

武飞扬头像
_黎晟
帮助1

前言

  • 使用allure生成测试报告,当报告存放路径相同时,报告数据是会累加,会导致测试报告内展示了之前运行的用例情况

  • 同理,当你的用例名称修改后,再次执行后,也会保留上一次的用例运行记录

不同用例文件,报告路径相同

准备 test_report_1.pytest_report_2.py 两个用例文件,内容如下:

#!/usr/bin/env python3
# -*- coding:utf-8 -*-

"""
    __File__   = test_report_1.py
    __Project__= _JAuto-Interface
    __Time__   = 2022-02-23 15:43:15
    __Author__ = 黎晟
"""


def test_case_1_1():
    """测试用例-1-1"""
    assert 1 == 1


def test_case_1_2():
    """测试用例-1-2"""
    assert 1 == 1
学新通
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

"""
    __File__   = test_report_2.py
    __Project__= _JAuto-Interface
    __Time__   = 2022-02-23 15:52:03
    __Author__ = 黎晟
"""


def test_case_2_1():
    """测试用例-2-1"""
    assert 1 == 1


def test_case_2_2():
    """测试用例-2-2"""
    assert 1 == 1
学新通

先执行test_report_1.py文件用例,查看测试报告

# 执行test_report_1.py
pytest --alluredir=./report/xml test_report_1.py

学新通

再执行test_report_2.py文件用例,查看测试报告

# 执行test_report_2.py
pytest --alluredir=./report/xml test_report_2.py

学新通

测试报告内会展示历史运行的用例1的内容,这不是想要的结果

相同用例文件,用例名称改变

修改test_report_1.py用例名称,如下:

#!/usr/bin/env python3
# -*- coding:utf-8 -*-

"""
    __File__   = test_report_1.py
    __Project__= _JAuto-Interface
    __Time__   = 2022-02-23 15:43:15
    __Author__ = 黎晟
"""


def test_case_11_1():
    """测试用例-11-1"""
    assert 1 == 1


def test_case_11_2():
    """测试用例-11-2"""
    assert 1 == 1
学新通

执行用例(命令同上),查看测试报告学新通

可以看到,test_report_1套件下,共用4条用例,包含了修改用例名称前的用例,也不是想要的结果

–clean-alluredir

用法
  • pytest 提供了 --clean-alluredir 命令行参数用来在生产测试报告前,清空历史执行记录
不同用例文件,相同报告路径情况
再次执行
# 执行test_report_1.py
pytest --alluredir=./report/xml test_report_1.py

# 执行test_report_2.py
pytest --alluredir=./report/xml test_report_2.py --clean-alluredir
查看测试报告

学新通

可以看到没有其他用例文件的执行记录了

相同用例文件,修改用例名称
同样的修改test_report_1.py文件,
# 修改test_report_1.py文件
def test_case_1_1():
    """测试用例-1-1"""
    assert 1 == 1


def test_case_1_2():
    """测试用例-1-2"""
    assert 1 == 1
重新运行,查看测试报告
pytest --alluredir=./report/xml test_report_2.py --clean-alluredir

学新通

可以看到没有修改前的执行记录了

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgceaih
系列文章
更多 icon
同类精品
更多 icon
继续加载