当前位置:网站首页>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测试报告就生成成功了
边栏推荐
猜你喜欢

面试攻略系列(三)-- 高级开发工程师面试问些啥?

Final assignment of R language data analysis in a university

The FPGA - work summary recently

GIN Bind mode to get parameters and form validation

FFmpeg multimedia file processing (implementation of ffmpeg operation directory and list)

蓝桥历届真题-门牌制作

Q_04_05 使用Qubits

Unity3d_API_GPS_LocationService

IDEA Gradle 常遇问题(一)

The sword refers to the offer, cuts the rope 2
随机推荐
GIN a preliminary study, the environment is installed
How to reduce the size of desktop icons after the computer is reinstalled
音频基础学习——声音的本质、术语与特性
ftplib+ tqdm upload and download progress bar
Q_07 词汇表
render解析
19、学习MySQL 索引
javscript基础易错点集合
记录本项目中用到的系统调用与C库函数-2
5G China unicom repeater network management protocol real-time requirements
Sandbox中的进程/线程相关-1
Q_04_07 进一步探索
43. The sword refers to Offer 1 ~ 1 the number of occurrences of n integers (recursive, mathematics)
CPU-MIPS32 instruction architecture (unlocked pipeline microprocessor)
FFmpeg multimedia file processing (FFMPEG logging system)
快来扔鸡蛋。
蓝桥历届真题-门牌制作
面试攻略系列(二)-- 秒杀系统
Q_06_05 文件结构
周末看点回顾|我国IPv6网络全面建成;2022昇腾AI开发者创享日·南京站成功举办…