前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >httprunner 2.x学习9-生成测试报告ExtentReport

httprunner 2.x学习9-生成测试报告ExtentReport

作者头像
上海-悠悠
发布2020-06-17 15:24:21
7480
发布2020-06-17 15:24:21
举报
文章被收录于专栏:从零开始学自动化测试

前言

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 目录。

运行 case 和 testsuites 目录下用例

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

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

代码语言:javascript
复制
!!!!!!!!!! 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 case testsuites —report-template reports/template/extent_report_template2.4.3.html

最终生成报告效果

下载地址

接下来小伙伴门最关心的是 extent_report_template2.4.3.html 在哪下载的问题了!

第一步先关注微信公众号:yoyoketang 回复:template 领取下载地址

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-06-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 遇到问题
  • 解决办法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档