zoukankan      html  css  js  c++  java
  • httprunner 2.x学习9-生成测试报告ExtentReport('dict object' has no attribute 'meta_data'问题已解决)

    前言

    httprunner 可以自定义生成测试报告的模板,1.x版本里面有个 extent_report_template.html 模块非常美观。
    但是生成报告的时候会报错:jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'meta_data'
    环境:httprunner==2.4.3

    遇到问题

    httprunner 2.x 版本已经去掉 extent_report_template.html 了,所以在Libsite-packageshttprunner emplates 下找不到。
    可以把1.x 版本里面的模块复制出来,在项目跟目录下新建一个 report目录,再新建 report/template 目录。

    运行 case 和 testsuites 目录下用例

    hrun case testsuites --report-template reports/template/extent_report_template.html

    运行后出现报错: jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'meta_data'

    !!!!!!!!!! exception stage: generate html report !!!!!!!!!!
    Traceback (most recent call last):
      File "E:python36lib
    unpy.py", line 193, in _run_module_as_main
        "__main__", mod_spec)
      File "E:python36lib
    unpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "D:softvenv_hrunScriptshrun.exe\__main__.py", line 7, in <module>
      File "d:softvenv_hrunlibsite-packageshttprunnercli.py", line 101, in main
        report_file=args.report_file
      File "d:softvenv_hrunlibsite-packageshttprunner
    eport.py", line 321, in gen_html_report
        ).render(summary)
      File "d:softvenv_hrunlibsite-packagesjinja2environment.py", line 1090, in render
        self.environment.handle_exception()
      File "d:softvenv_hrunlibsite-packagesjinja2environment.py", line 832, in handle_exception
        reraise(*rewrite_traceback_stack(source=source))
      File "d:softvenv_hrunlibsite-packagesjinja2\_compat.py", line 28, in reraise
        raise value.with_traceback(tb)
      File "<template>", line 264, in top-level template code
      File "d:softvenv_hrunlibsite-packagesjinja2environment.py", line 471, in getattr
        return getattr(obj, attribute)
    jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'meta_data'
    

    这个主要是 2.x 版本的生成的报告跟 1.x 不一样导致的。

    解决办法

    先找个适配2.x 版本的模板, 我试了下目前最高只能适配到 httprunner2.4.3 版本, 其他高点的版本不适配了。
    先降级 之前的httrunner2.5.7 版本,改成 httprunner2.4.3

    pip install httprunner==2.4.3 --index-url https://pypi.douban.com/simple

    版本降级后,把新的模板放到 report/template 目录,为了跟之前的区分开,这里模板名称改成 extent_report_template2.4.3.html

    再次运行用例

    hrun case testsuites --report-template reports/template/extent_report_template2.4.3.html

    最终生成报告效果

    下载地址

    接下来小伙伴门最关心的是 extent_report_template2.4.3.html 在哪下载的问题了!
    第一步先关注微信公众号:yoyoketang
    回复:template
    领取下载地址!

  • 相关阅读:
    Kubernets 第一讲 初探
    docker 运行nginx并进入容器内部、端口映射
    Docker 国内镜像的配置及使用
    Centos7上安装docker
    富文本编辑器--FCKEditor 上传图片
    在centos7上安装elasticSearch
    Centos7上卸载openJdk安装,安装自己的JDK1.8
    fastdfs 上传图片 完整版
    nginx 启动报错 “/var/run/nginx/nginx.pid" failed” 解决方法
    nginx + fastdfs 的开机自启动
  • 原文地址:https://www.cnblogs.com/yoyoketang/p/13121392.html
Copyright © 2011-2022 走看看