Appium 关于 pytest 的问题

Mr.tian · 2016年12月01日 · 最后由 Mr.tian 回复于 2016年12月05日 · 1261 次阅读

问题描述:

  • 我使用的是 appium+selenium 的模式,选择 pytest 测试框架。现在我有个需求想在用例执行完毕后,对生成的测试报告进行一些其它的操作,可是我不知道怎么做。怎么让 pytest 测试框架在运行结束后自动去调用我的操作代码
  • 我查了半天还是不知道怎么做,求大家指导一下
共收到 7 条回复 时间 点赞

路过的大侠,帮帮我吧🙏

匿名 #6 · 2016年12月01日

用 unittest,然后 pytest 执行,另外 pytest 还有一个插件 (pytest-html) 专门生成测试报告,你可以去用一下,个人感觉很好用

@Mr.Tian 你可以参考使用 pytest 的 hook 机制,文档在这里http://docs.pytest.org/en/latest/writing_plugins.html#writing-hook-functions

你可以在你的 conftest.py 中实现下面的这些 hook 函数,你可以自己选择一个符合你要求的 hook 函数来实现

pytest_itemcollected(item)[source]
we just collected a test item.

pytest_collectreport(report)[source]
collector finished collecting.

pytest_deselected(items)[source]
called for test items deselected by keyword.

pytest_report_header(config, startdir)[source]
return a string to be displayed as header info for terminal reporting.

pytest_report_teststatus(report)[source]
return result-category, shortletter and verbose word for reporting.

同 3 楼,通过 Hook 机制就可以完成你的需求了。

关于报告编辑的可以参考 pytest-html 的源码。

py 不会。。。

#3 楼 @cesc 已经解决了,谢谢!👍

#4 楼 @chenhengjie123 解决了!谢谢啦!

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册