背景:
allure报告很美观,但是发现在报告中环境经常显示为空没有任何东西,有时候需要在环境上加上一些东西做展示
第一步:需要先新增一个environment.properties文件,并在文件中添加环境参数,注意不能使用中文
Author=xxx
BaseUrl=https://baidu.com
ProjectName=FenMiApiFrame
PythonVersion=3.7.0
PytestVersion=7.4.4
AllureVersion=2.18.1
第二步:environment.properties文件需要放再reports下的temp文件
environment.properties文件需要放再reports下的temp文件,但是我们在执行脚本的时候经常会带上./reports/allure --clean参数会清除temp文件,所以需要把environment.properties文件放到根目录,然后再把根目录的environment.properties文件copy到temp文件下,这需要在运行文件增加一行copy代码
第三步:需要在运行文件上增加一行运行代码
os.system("copy environment.properties .\\reports\\temp")
import os
import time
import pytest
if __name__ == '__main__':
pytest.main()
time.sleep(1)
# os.system("allure generate ./reports/temp -o ./reports/allure --clean")
# copy environment.properties .\\reports\\temp 设置allure报告环境变量
os.system("copy environment.properties .\\reports\\temp")
os.system("allure generate ./reports/temp -o ./reports/allure --clean")