Execute code if a test fails with py.test

家住魔仙堡 提交于 2019-12-10 18:34:32

问题


I'm doing UI test automation on Android using Appium and py.test. I'd like to be able to save a bug report using adb after a test fails.

Is there a way to tell if a test fails in my test code so I can then run save the bug report in the teardown?

Originally, I was just going to save the bug report after each test, but it's a bit excessive adding 45 seconds to each test.


回答1:


You can implement a pytest_runtest_logreport hook in your conftest.py like this:

def pytest_runtest_logreport(report):
    if report.when == 'call' and report.failed:
        # save bug report

For more information, see Woking with plugins and conftest files.



来源:https://stackoverflow.com/questions/26259990/execute-code-if-a-test-fails-with-py-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!