Skip to content

Support for "exception message"-only property for pytest_runtest_logreport #3343

@whimboo

Description

@whimboo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions