pytest学习和使用21-测试报告插件allure-pytest如何使用?
创始人
2025-05-31 02:28:34
0

21-测试报告插件allure-pytest如何使用?

  • 1 Allure简介
  • 2 环境配置
    • 2.1 allure-pytest插件安装
    • 2.2 pytest安装
    • 2.3 allure文件下载
    • 2.4 allure环境变量配置
    • 2.5 配置java环境
  • 3 查看allure版本
  • 4 运行allure
    • 4.1 测试用例
    • 4.1 执行方法
    • 4.3 报告查看方法
    • 4.4 指定报告生成的端口
    • 4.5 切换报告语言
    • 4.6 查看报告重要信息
  • 5 allure报告结构说明

1 Allure简介

详细内容可以参考官方文档:https://docs.qameta.io/allure-report/;
在这里插入图片描述

  • Allure是一个多语言测试报告工具;
  • 可以使用Web形式显示报告内容;
  • 开发/质量保证角度,可以将测试失败划分为bug和损坏的测试,还可以配置log,step,fixture,attachments,timings,历史记录以及与TMS的集成以及Bug跟踪系统;
  • 管理人员角度,Allure提供了一个清晰的“全局”,涵盖了已涵盖的功能,缺陷聚集的位置,执行时间表的外观以及许多其他方便的事情;
  • Allure的模块化和可扩展性确保您始终能够微调某些东西,以使Allure更适合您。

重点:拓展功能需要在测试用例集上加装饰器(后续文章再学习)

2 环境配置

2.1 allure-pytest插件安装

pip3 install allure-pytest
C:\Users\Administrator>pip3 install allure-pytest
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: allure-pytest in d:\python37\lib\site-packages (2.8.12)
Requirement already satisfied: six>=1.9.0 in d:\python37\lib\site-packages (from allure-pytest) (1.15.0)
Requirement already satisfied: allure-python-commons==2.8.12 in d:\python37\lib\site-packages (from allure-pytest) (2.8.12)
Requirement already satisfied: pytest>=4.5.0 in d:\python37\lib\site-packages (from allure-pytest) (6.2.4)
Requirement already satisfied: attrs>=16.0.0 in d:\python37\lib\site-packages (from allure-python-commons==2.8.12->allure-pytest) (20.3.0)
Requirement already satisfied: pluggy>=0.4.0 in d:\python37\lib\site-packages (from allure-python-commons==2.8.12->allure-pytest) (0.13.1)
Requirement already satisfied: importlib-metadata>=0.12 in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (2.1.1)
Requirement already satisfied: iniconfig in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (1.1.1)
Requirement already satisfied: py>=1.8.2 in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (1.10.0)
Requirement already satisfied: packaging in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (20.8)
Requirement already satisfied: colorama in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (0.4.4)
Requirement already satisfied: atomicwrites>=1.0 in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (1.4.0)
Requirement already satisfied: toml in d:\python37\lib\site-packages (from pytest>=4.5.0->allure-pytest) (0.10.2)
Requirement already satisfied: zipp>=0.5 in d:\python37\lib\site-packages (from importlib-metadata>=0.12->pytest>=4.5.0->allure-pytest) (1.2.0)
Requirement already satisfied: pyparsing>=2.0.2 in d:\python37\lib\site-packages (from packaging->pytest>=4.5.0->allure-pytest) (2.4.7)

2.2 pytest安装

pip3 install pytest
  • 这个不多说了,之前已经安装过了。

2.3 allure文件下载

  • 下载地址:https://github.com/allure-framework/allure2/releases;
  • allure是一个命令行工具;
    在这里插入图片描述
  • 往下找,找到下载链接,这里使用的Windows操作系统,所以下载zip文件:
    在这里插入图片描述
  • 如果以上下载比较慢,可以使用以下地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/

2.4 allure环境变量配置

  • 下载后解压到本地即可,比如:
    在这里插入图片描述
D:\allure-2.21.0\bin
  • 然后把以上路径添加到系统环境变量中:
    在这里插入图片描述

2.5 配置java环境

  • 因为allure是依赖java环境的,所以还需要配置java变量;
  • 详细java环境配置可以直接网上搜索即可,或者查看本文有关java的配置:
    Jmeter安装配置详细教程。

3 查看allure版本

allure --version
C:\Users\Administrator>allure --version
2.13.2

4 运行allure

4.1 测试用例

# -*- coding:utf-8 -*-
# 作者:虫无涯
# 日期:2023/3/20 
# 文件名称:test_xxx.py
# 作用:示例
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelsonimport pytest
import timeclass 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_xxx.py"])

4.1 执行方法

  • 执行pytest -n auto --alluredir=xxx/xxx/xxx来运行查看测试结果,其中--alluredir是指定报告存放的路径,比如:
pytest -n auto --alluredir=allure
  • 我只运行以上代码,所以我指定了要运行的脚本为:test_xxx.py,报告存放路径在当前脚本的路径:
pytest -n auto --alluredir=allure test_xxx.py
  • 运行:
gw0 [9] / gw1 [9] / gw2 [9] / gw3 [9] / gw4 [9] / gw5 [9] / gw6 [9] / gw7 [9]
.........                                                                                               [100%]
============================================= 9 passed in 4.66s ==============================================

4.3 报告查看方法

  • 运行完成后在test_xxx.py的相同路径下,生成一个allure的文件夹:

在这里插入图片描述

  • 可以看到有很多文件,我们需要使用allure命令来显示测试报告:

在这里插入图片描述

allure serve allure
(venv) F:\pytest_study\test_case\test_j>allure serve allure
Generating report to temp directory...
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\743714976960418009\allure-report
Starting web server...
2023-03-20 11:16:28.270:INFO::main: Logging initialized @4392ms to org.eclipse.jetty.util.log.StdErrLog
Server started at . Press  to exit
  • 使用以上命令会自动打开报告,如下:
    在这里插入图片描述

4.4 指定报告生成的端口

  • 上边的运行方式,生成的端口是自动的随机的,那如何生成指定端口呢?如下:
allure serve -p 8888 allure

4.5 切换报告语言

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.6 查看报告重要信息

  • 查看测试套件:
    在这里插入图片描述
  • 查看运行图标数据:
    在这里插入图片描述
  • 查看用例执行时间:
    在这里插入图片描述
  • 查看用例数据:
    在这里插入图片描述

5 allure报告结构说明

在这里插入图片描述
在这里插入图片描述

字段说明
Overview报告总览
Categories类别,查看用例执行情况比如 failederror
Suites测试套件,根据packagemodule、类、方法来查找用例
Graphs测试结果图形 ,有分布图,优先级,耗时等
Timeline用例运行时间等
Behaviors行为驱动, 根据epic、feature、story来分组测试用例
Packages按照packagemodule来分组测试用例

相关内容

热门资讯

修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
【前端】‘??‘与‘||‘有什... 0 问题 经常写const data = res.data.a ?? ''或者const d...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
牛客计算器的改良(Python... 文章目录1.题目描述2.输入描述:3.输出描述:4.示例15.分析6.代码7.结语 链接࿱...
正大杯|市调大赛|2023备赛... 关键信息 同时随着精细化养宠趋势的深入,宠物消费类目日渐丰富。 本报告通过 Niuco...
QGIS下载在线地图(Goog... 前言 国内外有很多在线地图下载软件,但功能单一,基本上只能下载数据&#x...