httprunner 2.x学习9-生成测试报告ExtentReport(‘dict object‘ 问题已解决)

前言

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’

!!!!!!!!!! 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
领取下载地址!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值