我正在使用 pytest。
我想收集/保存一些数据,以便对测试失败进行事后分析。我可以写一个teardown_method
,但我没有看到在这种情况下获得测试状态的方法。
是否可以对任何测试采取行动(或assertion
) 失败?
实施一个pytest_exception_interact
in a conftest.py
文件,根据文档 https://docs.pytest.org/en/stable/reference.html?highlight=pytest_exception_interact#_pytest.hookspec.pytest_exception_interact:
当引发可以交互处理的异常时调用。
def pytest_exception_interact(node, call, report):
if report.failed:
# call.excinfo contains an ExceptionInfo instance
从您的问题中不清楚您想要从错误中收集什么,但可能可以访问ExceptionInfo
实例应该足以满足您的情况。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)