如果测试因py.test而失败,则执行代码

Cas*_*ass 3 python android adb pytest

我正在使用Appiumpy.test在Android上进行UI测试自动化.我希望能够在测试失败后使用adb保存错误报告.

有没有办法判断我的测试代码中的测试是否失败,以便我可以在拆解时运行保存错误报告?

最初,我只是在每次测试后保存错误报告,但每次测试增加45秒会有点过分.

Bru*_*ira 5

您可以在pytest_runtest_logreport此处实现一个钩子conftest.py:

def pytest_runtest_logreport(report):
    if report.when == 'call' and report.failed:
        # save bug report
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅使用插件和conftest文件进行Woking.