当前位置:网站首页>pytest 之 allure报告
pytest 之 allure报告
2022-08-09 13:06:00 【沉觞流年】
pytest 之 allure报告
Allure Framework 是一种灵活的轻量级多语言测试报告工具,不仅可以以简洁的Web报告形式非常简洁地显示已测试的内容,而且还允许参与开发过程的每个人从日常执行中提取最大程度的有用信息。测试
左侧给出了 allure 报告支持的语言和框架,点击对应的链接可了解相应的使用方法
安装allure
文档开头,给出了三种不同的操作系统的安装方式
还有通用方法,三种操作系统都可以通过该种方式进行安装
这里介绍的是采用通用方法在 Windows 下安装 allure
1、下载 allure.zip
点击文档上的链接,注意,要把请求方式换成 https。链接
选择最新的包下载
选择 zip 格式
这里也提供了github下载链接
2、解压到本地目录后配置环境变量
下载完成后,将文件进行解压,存放路径看个人,怎么方便怎么来
解压完成后,bin 目录下有两个文件,就是用来启动allure测试报告用的,Windows 下点击bat文件即可
为了能在命令行输入命令进行使用,需要配置allure.bat的环境变量
在命令行中运行allure,确认环境变量配置成功。
使用快捷键Win + R,输入 cmd ,打开黑屏终端,,输入命令 allure ,可以看到各种选项,说明环境变量配置成功
与 pytest 集成
与 pytest 集成,需要 pytest 执行用例后,生成 allure 能够解析的测试结果文件
1、安装 allure-pytest 插件
使用命令安装 allure-pytest 插件
pip install allure-pytest
2、生成 allure 报告
1. 通过命令生成 allure 能够解析的测试结果文件
pytest --alluredir=/tmp/my_allure_results
/tmp/my_allure_results 为测试报告文件所在路径
该命令的参数可以和运行测试用例的参数一起执行
这里就不通过命令行的方式生成对应的文件,而是通过 run.py 的方式执行
run.py
import pytest
pytest.main(["-s","-v","-m","demo","--html=Outputs/reports/report.html","--reruns","2","--reruns-delay","5","--alluredir=Outputs/allure_reports"])
运行 run.py 文件后,可以看到,allure_reports 目录下生成了一堆测试结果文件,里面记录的都是关于测试用例的执行情况
可以优化一下,按日期生成文件
import pytest
from Common import logger
html_report = "Outputs/reports/report_{}_test.html".format(logger.curTime)
allure_report_dir = "Outputs/reports/allure_report_{}".format(logger.curTime)
pytest.main(["-s","-v","-m","demo","--html={}".format(html_report),"--reruns","2","--reruns-delay","5","--alluredir={}".format(allure_report_dir)])
2. 生成 allure 测试报告
进入项目根目录下,输入命令
allure serve /tmp/my_allure_results
这里测试报告文件所在路径为 Outputs/allure_reports,所以我的命令为
allure serve Outputs/allure_reports

生成成功后,如果没有自动弹出测试报告,可以点击链接,打开测试报告文件
allure测试报告就生成成功了
边栏推荐
- 面试攻略系列(三)-- 高级开发工程师面试问些啥?
- How to reduce the size of desktop icons after the computer is reinstalled
- JZ7 重建二叉树
- RTSP协议的实现
- NC61 两数之和
- FFmpeg多媒体文件处理(ffmpeg打印音视频Meta信息)
- NFS pays special attention to the problem of permissions
- 5G China unicom repeater network management protocol real-time requirements
- FFMPEG multimedia file processing (deletion and renaming of ffmpeg files)
- Q_04_05 使用Qubits
猜你喜欢
随机推荐
RTSP协议讲解
The sword refers to Offer 56 - II. Number of occurrences of a number in an array II (bit operation)
陈强教授《机器学习及R应用》课程 第十五章作业
GIN Bind模式获取参数和表单验证
NC193 二叉树的前序遍历
Q_07 词汇表
Professor Chen Qiang the machine learning and R application course chapter 18 assignments
Come and throw eggs.
蓝桥历届真题-门牌制作
WPF 系统托盘 图标闪烁
Dry+Bean+Dataset R语言数据分析,报告英文
Unity3d_API_GPS_LocationService
FFmpeg多媒体文件处理(FFMPEG日志系统)
音视频录入的pts和dts问题
FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)
ftplib+ tqdm upload and download progress bar
Professor Chen Qiang "application in machine learning and R" course chapter 17
5G China unicom AP:B SMS ASCII Transcoding Requirements
利用信号灯和共享内存实现进程间同步通信
行程和用户[阅读理解法]









