在 allure 报告首页 ENVIRONMENT 显示 ‘There are no environment variables’ 没有环境变量的配置信息。
环境变量配置可以添加报告相关的配置参数,如运行的系统环境,版本号,测试环境,测试人员等基本信息
environment 配置文件
方法一:environment.properties 文件
在allure的report根目录下添加一个 environment.properties 文件,配置文件不能放置中文,否则会出现乱码
System=MAC
PythonVersion=3.8.5
AllureVersion=2.15.0
BaseUrl=http://xxxxxx:8081/
Project=IAM
author=nan.luo
email=nan.luo@xxxx.com
在运行 pytest 生成 allure 报告的时候,有时候需要加 --clean 参数,清楚之前的报告记录,这样会之前清空 report 目录,environment.properties文件也会被删除。
为了不让 environment.properties 文件删除掉,可以把 environment.properties 文件放项目根目录,在运行报告的时候,先 copy 到 report 目录
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import subprocess
WIN = sys.platform.startswith('win')
def main():
"""
"""
steps = [
"venv\\Script\\activate" if WIN else "source venv/bin/activate",
"pytest --alluredir allure-results --clean-alluredir",
"copy environment.properties report\\environment.properties" if WIN else "cp config/environment.properties allure-results/environment.properties",
"allure generate allure-results -c -o allure-report",
"allure open allure-report"
]
for step in steps:
subprocess.run("call " + step if WIN else step, shell=True)
if __name__ == "__main__":
# 生成pytest-html的日志
# pytest --html ../report/report.html --self-contained-html
main()