前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~

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

原创
作者头像
虫无涯
发布2023-04-03 09:47:08
4160
发布2023-04-03 09:47:08
举报
文章被收录于专栏:全栈测试技术全栈测试技术

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

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

2 看个简单的例子

2.1 运行一个用例

  • 该目录下有3个脚本,目前没有报告;
在这里插入图片描述
在这里插入图片描述
  • 脚本1:test_assume.py,使用命令:pytest -n auto --alluredir=allure test_assume.py运行:
代码语言:python
复制
# -*- 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
代码语言:python
复制
# -*- 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:
代码语言:python
复制
pytest -n auto --alluredir=allure test_assume.py
在这里插入图片描述
在这里插入图片描述
  • 再运行脚本2,此时加上命令行参数--clean-alluredir,清空脚本1的记录,且只保留脚本2的报告:
代码语言:python
复制
pytest -n auto --alluredir=allure test_xdist.py --clean-alluredir
在这里插入图片描述
在这里插入图片描述

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

  • 使用pytest -h
代码语言:python
复制
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即可:
代码语言:python
复制
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.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 为什么要进行allure历史记录清空?
  • 2 看个简单的例子
    • 2.1 运行一个用例
      • 2.2 运行两个用例
      • 3 那如何进行allure报告历史数据清空呢?
        • 3.1 最直接的方法
          • 3.2 使用命令行参数--clean-alluredir进行清空
          • 4 查看--clean-alluredir 参数说明
          • 5 关于allure的其他命令行参数
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档