执行code如果测试失败,py.test [英] Execute code if a test fails with py.test
问题描述
我在Android上使用 Appium 并的 py.test 。我希望能够保存使用 ADB bug报告后,测试失败。
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.
有没有办法判断一个测试在我的测试code失败,这样我就可以再运行保存在拆解错误报告?
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?
本来,我正要每次测试后保存错误报告,但它是一个有点过分增加45秒每个测试。
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.
推荐答案
您可以在您的 conftest.py $一个
pytest_runtest_logreport
挂钩C $ C>是这样的:
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
有关详细信息,请参阅沃金与插件和conftest文件。
For more information, see Woking with plugins and conftest files.
这篇关于执行code如果测试失败,py.test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!