You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for "exception message"-only property for pytest_runtest_logreport #3343
We have a custom report class defined which uses the pytest_runtest_logreport hook to handle test results, and to build a test report based on our needs. For one of the reports only the exception message is used as summary. Sadly the passed in report instance for pytest_runtest_logreport doesn't contain such a property. Instead report.longreprtext has to be used (which includes the full stack trace) to extract just the error line:
class SubtestResultRecorder(object):
def __init__(self):
self.results = []
def pytest_runtest_logreport(self, report):
if report.failed && report.when != "call":
message = ""
for line in report.longreprtext.splitlines():
if line.startswith("E "):
message = line[1:].strip()
break
[...]
This doesn't seem to be very stable and might break if pytest changes the formatting.
So it would be great if there could be a property like report.exc_message which would hold only the assertion message.
Would it make sense to have the exception object instead? That way you can get the exception message anyway. Fancy trying to create a patch to do this?
Can we close this in favor of #3399? It boils down to improve the report object to contain more information, keeping in mind that this needs to be transferred over the wire by xdist.
Activity
pytestbot commentedon Mar 26, 2018
GitMate.io thinks possibly related issues are #2631 (Support PEP-415's Exception.suppress_context), #1270 (poor exception handling of monkeypatch.setattr on property-decorated attributes), #3144 (Exit exception), #1877 (test_suite support), and #264 (testressources support).
flub commentedon Mar 26, 2018
Would it make sense to have the exception object instead? That way you can get the exception message anyway. Fancy trying to create a patch to do this?
brianmaissy commentedon Apr 2, 2018
Would something like this work?
RonnyPfannschmidt commentedon Apr 2, 2018
for a correct solution you would need into pytest_makrereport, and transfer the new metadata to a report section or a set of report section
nicoddemus commentedon Sep 2, 2018
Can we close this in favor of #3399? It boils down to improve the report object to contain more information, keeping in mind that this needs to be transferred over the wire by xdist.