本文主要是介绍pytest测试框架中allure定制报告中添加环境配置展示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
背景:
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 pytestif __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")
最后展示效果:
这篇关于pytest测试框架中allure定制报告中添加环境配置展示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!