pytest之allure(八)之清空上一次运行的记录(--clean-alluredir)【清空的是测试报告的原始数据(json/text/attach),而不是generate生成测试报告后的report数据】

前言

当我们使用allure生成测试报告之后,我们再修改测试用例,然后再次运行生成测试报告会发现测试报告中保留了上一次用例的运行记录。【默认allure测试报告不会清理之前的原始数据;而原来的原始数据会在最新的allure测试报告中显示历史用例执行结果】

如果我们不想看到原来的用例执行记录,而是生成新的测试报告,我们可以在用例执行的时候在命令行中通过指定--clean-alluredir参数来做到每次都生成新的测试报告。

allure会保留历史执行记录:

当多次执行测试用例的时候,我们会发现allure的测试报告当中保留了我们每次执行的记录,通过这种方式我们可以清晰的看到用例每次的运行情况。但是同样也带来了一个问题,那就是我们每次修改用例或者新增了用例,或者说只想执行某个用例,生成报告之后我们仍然会看到之前的用例报告,而不是当前最新的报告。

指定--clean-alluredir参数清空上一次执行记录:

如果我们想每次执行用例的时候都生成新的测试报告,那么我们可以在命令中加上--clean-alluredir参数。

与报告相关的三个参数,命令行中使用pytest -h查看:

  •  --alluredir=DIR:指定测试报告的生成路径;
  • --clean-alluredir:如果已经存在报告,那就先清空,然后再生成新的测试报告;
  • --allure-no-capture:不添加pytest捕捉的logging/stdout/stderr到测试报告中;

加上--clean-alluredir参数重新执行下测试用例:

> pytest --alluredir=./report/result_data --clean-alluredir
>
allure generate report/tmp -o report/allure-report -c report/allure-report
> allure serve ./report/result_data

查看测试报告:

举例

生成allure测试报告时么没有添加 --clean-alluredir 命令行参数的情况:

pytest 运行测试用例生成 allure 报告时,当测试用例名称修改后重新运行,会保留历史运行记录:

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 运行: pytet test_1.py --alluredir=./allure 

allure 报告:只有两条用例

修改后的 test_1.py 的代码

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

再次运行命令,查看 allure 报告:四条用例,包含了历史的两条,这不是我们希望看到的

 

posted @ 2021-08-20 09:01  习久性成  阅读(1032)  评论(0编辑  收藏  举报