allure报告环境配置(environment)
一、功能描述
allure 报告首页展示的 "环境" 显示“没有环境变量” 配置信息,为了让allure 报告首页展示的信息更全面,需要进行设置。设置方法如下:
二、设置步骤
1、旧版本设置方法
老版本的allure可以采用如下方式:
import allure
# allure 添加 environment 配置
allure.environment(blog='https://www.cnblogs.com/xyztank/')
2、新版本设置方法
- 创建文件
新版本的allure需要在allure报告的根目录创建environment.properties
文件,创建文件:
- 填充环境变量
systemVersion=win10
pythonVersion=3.7.0
allureVersion=2.13.15
baseUrl=https://www.cnblogs.com/xyztank/
projectName=upl
author=xtank
三、复制配置文件
在执行pytest
命令生成allure
报告的时候,经常会加 --clean-alluredir
参数,其功能即是清除之前创建的报告,但此命令会将environment.properties
文件删除。为防止environment.properties
文件被删掉,可以把它放在项目根目录,在运行报告的时候,先 copy 到 report 目录。
addopts = -v -s --alluredir=F:/test_code_project/opra-upl/report/allure --clean-alluredir --reruns 3
复制命令如下:
#第一步执行测试
pytest test01.py
#第二步复制环境变量文件
copy environment.properties report\allure\environment.properties
#第三步生成报告
allure serve report/allure
参考
1、allure下载地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
2、官方地址:https://github.com/allure-framework/allure2/releases