Pytest安装Allure生成自动化测试报告

Date: 2025.01.09 16:33:01 author: lijianzhan

Allure 是一个强大的测试报告框架,能够生成美观且详细的测试报告。它与 pytest 结合使用,可以帮助你更好地展示测试结果、分析测试数据,并提高测试的可读性和可维护性。以下是关于如何在 Python 中使用 Allure 的详细指南,包括安装、配置、注解和生成报告。

  1. 安装 Allure
    allure-pytest 是 pytest 的插件,用于生成 Allure 报告,安装命令如下:
bash 复制代码
pip install allure-pytest
  1. 安装 Allure 命令行工具
    Allure 报告需要 Allure 命令行工具来生成和展示,下载地址
    2.1 Windows
    2.2 下载 Allure 命令行工具:Allure 下载页面
    2.3 解压并配置环境变量:
    2.4 将 bin 目录添加到系统的 PATH 环境变量中。

    2.5 macOS
    2.6 使用 Homebrew 安装:
bash 复制代码
brew install allure
  1. 验证安装命令如下:
bash 复制代码
allure --version
  1. 配置 pytest,修改 pytest.ini文件,在项目根目录下创建或修改 pytest.ini 文件,配置 Allure 报告的输出目录
python 复制代码
[pytest]
addopts = -v -s --alluredir=./allure-results
  1. 生成并查看报告,使用 Allure 命令行工具生成并查看报告:
python 复制代码
allure serve ./allure-results


相关推荐
Warson_L9 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅9 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅10 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L10 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅10 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L11 小时前
python的类&继承
python
Warson_L11 小时前
类型标注/type annotation
python
ThreeS13 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵15 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏