allure-05-生成html报告

一、根据xml生成html报告

方式一(命令行):

allure generate ./reports/xml -o ./reports/html --clean
字段 含义
allure 调用allure程序
generate 生成报告
./reports/xml 报告的xml数据源路径
-o 参数名,后面跟html报告存储路径
./reports/html 参数值,指定html报告存储路径

方式二(代码):

  1. allure没提供pytest一样的main方法
  2. 需要先写cmd命令
  3. 再调用标准库执行cmd命令
  4. 此处的
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

二、查看html报告

1. 找到html报告路径

image.png

2. 打开index.html

image.png

3. 浏览器打开

image.png

4. 设置成中文

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容