Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
whimboo opened this issue Mar 26, 2018 · 5 comments
Closed
Labels
topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity

Comments

@whimboo
Copy link

whimboo commented Mar 26, 2018

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.

@pytestbot
Copy link
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).

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Mar 26, 2018
@flub
Copy link
Member

flub commented 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?

@blueyed blueyed added type: enhancement new feature or API change, should be merged into features branch and removed type: bug problem that needs to be addressed labels Mar 26, 2018
@brianmaissy
Copy link
Contributor

Would something like this work?

@RonnyPfannschmidt
Copy link
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

@RonnyPfannschmidt RonnyPfannschmidt added type: question general question, might be closed after 2 weeks of inactivity topic: reporting related to terminal output and user-facing messages and errors and removed type: enhancement new feature or API change, should be merged into features branch labels Apr 2, 2018
@nicoddemus
Copy link
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
Labels
topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

7 participants