一、根据xml生成html报告
方式一(命令行):
allure generate ./reports/xml -o ./reports/html --clean
字段 | 含义 |
---|---|
allure | 调用allure程序 |
generate | 生成报告 |
./reports/xml | 报告的xml数据源路径 |
-o | 参数名,后面跟html报告存储路径 |
./reports/html | 参数值,指定html报告存储路径 |
方式二(代码):
- allure没提供pytest一样的main方法
- 需要先写cmd命令
- 再调用标准库执行cmd命令
- 此处的
from tools import log_tool
from tools import Shell
import pytest
if __name__ == '__main__':
# 自定义log工具
log = log_tool.MyLog()
xml_report_path = './reports/xml/'
html_report_path = './reports/html/'
pytest.main(['-s', '-q', '--alluredir',
xml_report_path,'./test_case/test_user.py'])
# 自定义shell工具
shell = Shell.Shell()
cmd = "allure generate %s -o %s --clean"%(xml_report_path,html_report_path)
try:
shell.invoke(cmd)
except Exception:
log.error('执行用例失败,请检查环境配置')
raise