pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~

简介: pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~

1 为什么要进行allure历史记录清空?

  • 没运行一次生成报告的命令,在allure报告的目录下就生成一次报告记录;
  • 如果进行很多次调试,那就有很多个报告历史记录;
  • 这样每次查看报告时就会显示历史的用例运行情况,比较乱且可能不是我们想要的结果;
  • 所以就需要对allure报告历史记录进行清空操作。

2 看个简单的例子

2.1 运行一个用例

  • 该目录下有3个脚本,目前没有报告;

在这里插入图片描述

  • 脚本1:test_assume.py,使用命令:pytest -n auto --alluredir=allure test_assume.py运行:
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/16 
# 文件名称:test_assume.py
# 作用:pytest-assume插件的使用
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson

import pytest

def test_case01():
    a = 100
    b = 200
    pytest.assume(a + b < 100)
    pytest.assume(a - b > 0)
    pytest.assume(a * b == 20000)
    pytest.assume(a / b == 200)
    pytest.assume((b - a) / a == 1)
    print("执行到这了~~~~~~~~~~")


if __name__ == '__main__':
    pytest.main(["-s", "test_assume.py"])
  • 脚本1运行后的allure报告如下,可以看见只有一个用例结果:

在这里插入图片描述

2.2 运行两个用例

  • 我们在之前的基础上,不删除allure的报告数据,直接运行脚本2:test_xdist.py,运行命令为:pytest -n auto --alluredir=allure test_xdist.py
# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/16 
# 文件名称:test_xdist.py
# 作用:pytest-xdist分布式测试
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson

import pytest
import time

class TestCase01():
    def test_case_01(self):
        time.sleep(1)
        print("case01$$$$$$$$$$$$$$$$$$$$$")

    def test_case_02(self):
        time.sleep(1)
        print("case02$$$$$$$$$$$$$$$$$$$$$")

    def test_case_03(self):
        time.sleep(1)
        print("case03$$$$$$$$$$$$$$$$$$$$$")

    def test_case_04(self):
        time.sleep(1)
        print("case04$$$$$$$$$$$$$$$$$$$$$")

    def test_case_05(self):
        time.sleep(1)
        print("case05$$$$$$$$$$$$$$$$$$$$$")

    def test_case_06(self):
        time.sleep(1)
        print("case06$$$$$$$$$$$$$$$$$$$$$")

class TestCase02():
    def test_case_07(self):
        time.sleep(1)
        print("case07$$$$$$$$$$$$$$$$$$$$$")

    def test_case_08(self):
        time.sleep(1)
        print("case08$$$$$$$$$$$$$$$$$$$$$")

    def test_case_09(self):
        time.sleep(1)
        print("case08$$$$$$$$$$$$$$$$$$$$$")


if __name__ == '__main__':
    pytest.main(["-s", "test_xdist.py"])
  • 查看allure报告内容,即包含了脚本的报告,也包含了脚本2的报告:

在这里插入图片描述

  • 那实际情况,我们可能只想看脚本2的数据,所以这就造成了allure报告历史数据不断的生成。

3 那如何进行allure报告历史数据清空呢?

3.1 最直接的方法

  • 那就是在运行脚本2的时候,直接删除allure目录;
  • 这种方式太不友好了,用起来也比较low了;

3.2 使用命令行参数--clean-alluredir进行清空

  • 我们先手动删除allure目录;

在这里插入图片描述

  • 先运行脚本1:
pytest -n auto --alluredir=allure test_assume.py

在这里插入图片描述

  • 再运行脚本2,此时加上命令行参数--clean-alluredir,清空脚本1的记录,且只保留脚本2的报告:
pytest -n auto --alluredir=allure test_xdist.py --clean-alluredir

在这里插入图片描述

4 查看--clean-alluredir 参数说明

  • 使用pytest -h
reporting:
  --alluredir=DIR       Generate Allure report in the specified directory (may not exist)
  --clean-alluredir     Clean alluredir folder if it exists
  --allure-no-capture   Do not attach pytest captured logging/stdout/stderr to report

5 关于allure的其他命令行参数

  • 使用allure -h即可:
C:\Users\Administrator>allure -h
Could not parse arguments: Expected a command, got -h
Usage: allure [options] [command] [command options]
  Options:
    --help
      Print commandline help.
    -q, --quiet
      Switch on the quiet mode.
      Default: false
    -v, --verbose
      Switch on the verbose mode.
      Default: false
    --version
      Print commandline version.
      Default: false
  Commands:
    generate      Generate the report
      Usage: generate [options] The directories with allure results
        Options:
          -c, --clean
            Clean Allure report directory before generating a new one.
            Default: false
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.
          -o, --report-dir, --output
            The directory to generate Allure report into.
            Default: allure-report

    serve      Serve the report
      Usage: serve [options] The directories with allure results
        Options:
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0
          --profile
            Allure commandline configuration profile.

    open      Open generated report
      Usage: open [options] The report directory
        Options:
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0

    plugin      Generate the report
      Usage: plugin [options]
        Options:
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.
目录
相关文章
|
21天前
|
存储 安全 Linux
|
9月前
|
测试技术
23-pytest-清空allure历史报告
23-pytest-清空allure历史报告
|
9月前
|
测试技术
29-pytest-运行上次失败用例
29-pytest-运行上次失败用例
|
测试技术
Pytest 系列(26)- 清空 allure 历史报告记录
Pytest 系列(26)- 清空 allure 历史报告记录
499 0
Pytest 系列(26)- 清空 allure 历史报告记录
如何给Airtest脚本/报告增加log记录
如何给Airtest脚本/报告增加log记录
621 0
|
测试技术
Pytest 系列(25)- @allure.severity 标记用例级别
Pytest 系列(25)- @allure.severity 标记用例级别
201 0
Pytest 系列(25)- @allure.severity 标记用例级别
|
测试技术
Cypress系列(57)- 删除等待代码
Cypress系列(57)- 删除等待代码
103 0
|
JavaScript
Cypress系列(20)- 可操作类型的命令 之 clear()
Cypress系列(20)- 可操作类型的命令 之 clear()
177 0
Cypress系列(20)- 可操作类型的命令 之 clear()
|
测试技术 Python
Pytest系列(13)- 重复执行用例插件之pytest-repeat的详细使用
Pytest系列(13)- 重复执行用例插件之pytest-repeat的详细使用
229 0
Pytest系列(13)- 重复执行用例插件之pytest-repeat的详细使用
|
安全 Linux
5 种方法重复执行历史命令
5 种方法重复执行历史命令
186 0