Skip to content

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

Closed

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.

Activity

  1. pytestbot commented on Mar 26, 2018

    @pytestbot
    Contributor

    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).

  2. flub commented on Mar 26, 2018

    @flub
    Member

    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?

  3. added
    type: enhancementnew feature or API change, should be merged into features branch
    and removed
    type: bugproblem that needs to be addressed
    on Mar 26, 2018
  4. brianmaissy commented on Apr 2, 2018

    @brianmaissy
    Contributor

    Would something like this work?

  5. RonnyPfannschmidt commented on Apr 2, 2018

    @RonnyPfannschmidt
    Member

    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

  6. added
    type: questiongeneral question, might be closed after 2 weeks of inactivity
    topic: reportingrelated to terminal output and user-facing messages and errors
    and removed
    type: enhancementnew feature or API change, should be merged into features branch
    on Apr 2, 2018
  7. nicoddemus commented on Sep 2, 2018

    @nicoddemus
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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