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 了,所以在\Lib\site-packages\httprunner\templates 下找不到。
可以把1.x 版本里面的模块复制出来,在项目跟目录下新建一个 report目录,再新建 report/template 目录。

运行 testsuites 目录下用例

hrun 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:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "E:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\soft\venv_hrun\Scripts\hrun.exe\__main__.py", line 7, in <module>
  File "d:\soft\venv_hrun\lib\site-packages\httprunner\cli.py", line 101, in main
    report_file=args.report_file
  File "d:\soft\venv_hrun\lib\site-packages\httprunner\report.py", line 321, in gen_html_report
    ).render(summary)
  File "d:\soft\venv_hrun\lib\site-packages\jinja2\environment.py", line 1090, in render
    self.environment.handle_exception()
  File "d:\soft\venv_hrun\lib\site-packages\jinja2\environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "d:\soft\venv_hrun\lib\site-packages\jinja2\_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 264, in top-level template code
  File "d:\soft\venv_hrun\lib\site-packages\jinja2\environment.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 testsuites --report-template reports/template/extent_report_template2.4.3.html

最终生成报告效果

下载地址

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

2.5.7版本在github下载https://github.com/FuckyouBB/extent_report_template_httprunner2


httprunner 2.x实战教程点我 ->立即报名

posted @ 2020-06-13 18:49  上海-悠悠  阅读(1990)  评论(2编辑  收藏  举报