Pytest 系列(26)- 清空 allure 历史报告记录

简介: Pytest 系列(26)- 清空 allure 历史报告记录

如果你还想从头学起Pytest,可以看看这个系列的文章哦!

https://www.cnblogs.com/poloyy/category/1690628.html

 

背景


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

 

目录结构

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

image.png


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

test_1.py 的代码


#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__  = 
__Time__   = 2020/10/28 11:03
__Author__ = 小菠萝测试笔记
__Blog__   = https://www.cnblogs.com/poloyy/
"""
def test_1():
    print("test_1 文件的测试用例1")
def test_2():
    print("test_1 文件的测试用例2")


运行命令

进入该目录下,cmd 运行

pytest test_1.py --alluredir=./allure

 

allure 报告

image.png

只有两条用例

 

修改后的 test_1.py 的代码

def test_11():

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



def test_22():

   print("test_1 文件的测试用例2")

 

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

image.png


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

 

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


test_2.py 的代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__  = 
__Time__   = 2020/10/28 11:03
__Author__ = 小菠萝测试笔记
__Blog__   = https://www.cnblogs.com/poloyy/
"""
def test_1():
    print("test_1 文件的测试用例1")
def test_2():
    print("test_1 文件的测试用例2")


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

# 先运行第一个

pytest test_1.py --alluredir=./allure


# 再运行第二个,此时应该希望 allure 报告只有 test_2.py 的测试用例

pytest test_2.py --alluredir=./allure

 

查看 allure 报告

image.png

--clean-alluredir 参数


前言

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

 

pytest -h

image.png


将上面的栗子重新运行

# 先运行第一个

pytest test_1.py --alluredir=./allure


# 再运行第二个,此时应该希望 allure 报告只有 test_2.py 的测试用例

pytest test_2.py --alluredir=./allure --clean-alluredir

 

运行结果

image.png


相关文章
|
3月前
|
API
如何把自定义的函数,记录到你的Airtest报告里
如何把自定义的函数,记录到你的Airtest报告里
|
7月前
|
缓存 Python
【python脚本】word批注状态批量提取器V1版本
【python脚本】word批注状态批量提取器V1版本
|
10月前
|
测试技术
23-pytest-清空allure历史报告
23-pytest-清空allure历史报告
36-pytest-allure报告添加文本、截图信息
36-pytest-allure报告添加文本、截图信息
|
10月前
|
测试技术
29-pytest-运行上次失败用例
29-pytest-运行上次失败用例
|
移动开发 测试技术
pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~
pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~
90 0
pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~
jira学习案例38-清除警告信息
jira学习案例38-清除警告信息
57 0
jira学习案例38-清除警告信息
|
监控 Linux API
使用python时刻中监控文件夹,记录文件夹中文件异常信息
使用python时刻中监控文件夹,记录文件夹中文件异常信息
382 0
使用python时刻中监控文件夹,记录文件夹中文件异常信息
如何给Airtest脚本/报告增加log记录
如何给Airtest脚本/报告增加log记录
622 0