Reputation: 1750
I'm using pytest.
I would like to gather/save some data for postmortem analysis on a test failure. I can write a teardown_method
, but I don't see a way to obtain test status in that context.
Is it possible to take an action on any test (or assertion
) failure?
Upvotes: 11
Views: 12957
Reputation: 15255
Implement a pytest_exception_interact
in a conftest.py
file, which according to the documentation:
called when an exception was raised which can potentially be interactively handled.
def pytest_exception_interact(node, call, report):
if report.failed:
# call.excinfo contains an ExceptionInfo instance
It's not clear from your question exactly what you want to gather from the error, but probably having access to an ExceptionInfo
instance should be enough for your case.
Upvotes: 17