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

简介: pytest学习和使用21-测试报告插件allure-pytest如何使用?

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文件下载

在这里插入图片描述

  • 往下找,找到下载链接,这里使用的Windows操作系统,所以下载zip文件:

在这里插入图片描述

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/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_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 <http://172.16.1.33:13959/>. Press <Ctrl+C> 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来分组测试用例
目录
相关文章
|
2月前
|
数据采集 JSON JavaScript
Cypress 插件实战:让测试更稳定,不再“偶尔掉链子”
本文分享如何通过自定义Cypress插件解决测试不稳定的痛点。插件可实现智能等待、数据预处理等能力,替代传统硬性等待,有效减少偶发性失败,提升测试效率和可维护性。文内包含具体实现方法与最佳实践。
|
3月前
|
人工智能 边缘计算 搜索推荐
AI产品测试学习路径全解析:从业务场景到代码实践
本文深入解析AI测试的核心技能与学习路径,涵盖业务理解、模型指标计算与性能测试三大阶段,助力掌握分类、推荐系统、计算机视觉等多场景测试方法,提升AI产品质量保障能力。
|
安全 关系型数据库 测试技术
学习Python Web开发的安全测试需要具备哪些知识?
学习Python Web开发的安全测试需要具备哪些知识?
285 61
|
10月前
|
存储 人工智能 编译器
【03】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-测试hello word效果-虚拟华为手机真机环境调试-为DevEco Studio编译器安装中文插件-测试写一个滑动块效果-介绍诸如ohos.ui等依赖库-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
【03】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-测试hello word效果-虚拟华为手机真机环境调试-为DevEco Studio编译器安装中文插件-测试写一个滑动块效果-介绍诸如ohos.ui等依赖库-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
618 10
【03】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-测试hello word效果-虚拟华为手机真机环境调试-为DevEco Studio编译器安装中文插件-测试写一个滑动块效果-介绍诸如ohos.ui等依赖库-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
|
11月前
|
存储 测试技术 API
pytest接口自动化测试框架搭建
通过上述步骤,我们成功搭建了一个基于 `pytest`的接口自动化测试框架。这个框架具备良好的扩展性和可维护性,能够高效地管理和执行API测试。通过封装HTTP请求逻辑、使用 `conftest.py`定义共享资源和前置条件,并利用 `pytest.ini`进行配置管理,可以大幅提高测试的自动化程度和执行效率。希望本文能为您的测试工作提供实用的指导和帮助。
1092 15
|
自然语言处理 机器人 Python
ChatGPT使用学习:ChatPaper安装到测试详细教程(一文包会)
ChatPaper是一个基于文本生成技术的智能研究论文工具,能够根据用户输入进行智能回复和互动。它支持快速下载、阅读论文,并通过分析论文的关键信息帮助用户判断是否需要深入了解。用户可以通过命令行或网页界面操作,进行论文搜索、下载、总结等。
342 1
ChatGPT使用学习:ChatPaper安装到测试详细教程(一文包会)
|
前端开发 JavaScript 安全
学习如何为 React 组件编写测试:
学习如何为 React 组件编写测试:
147 2
|
编解码 安全 Linux
网络空间安全之一个WH的超前沿全栈技术深入学习之路(10-2):保姆级别教会你如何搭建白帽黑客渗透测试系统环境Kali——Liinux-Debian:就怕你学成黑客啦!)作者——LJS
保姆级别教会你如何搭建白帽黑客渗透测试系统环境Kali以及常见的报错及对应解决方案、常用Kali功能简便化以及详解如何具体实现
|
人工智能 安全 Linux
网络空间安全之一个WH的超前沿全栈技术深入学习之路(4-2):渗透测试行业术语扫盲完结:就怕你学成黑客啦!)作者——LJS
网络空间安全之一个WH的超前沿全栈技术深入学习之路(4-2):渗透测试行业术语扫盲完结:就怕你学成黑客啦!)作者——LJS
|
安全 大数据 Linux
网络空间安全之一个WH的超前沿全栈技术深入学习之路(3-2):渗透测试行业术语扫盲)作者——LJS
网络空间安全之一个WH的超前沿全栈技术深入学习之路(3-2):渗透测试行业术语扫盲)作者——LJS