(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.
标签:24,Allure,--,pytest,test,allure,report
From: https://blog.51cto.com/NoamaNelson/6165565