Skip to content

summary/OutcomeException: add support for short_msg#6003

Closed
blueyed wants to merge 1 commit intopytest-dev:featuresfrom
blueyed:summary-short_msg
Closed

summary/OutcomeException: add support for short_msg#6003
blueyed wants to merge 1 commit intopytest-dev:featuresfrom
blueyed:summary-short_msg

Conversation

@blueyed
Copy link
Contributor

@blueyed blueyed commented Oct 19, 2019

This is meant to improve the short msg with -r, where you want to see
the non-matched line, and not the first line (that might have matched),
from pytester's _match_lines.

This also improves __str__ / __repr__.

TODO:

  • use it for doctests (ReprFailDoctest,
    def repr_failure(self, excinfo):
    import doctest
    failures = None
    if excinfo.errisinstance((doctest.DocTestFailure, doctest.UnexpectedException)):
    failures = [excinfo.value]
    elif excinfo.errisinstance(MultipleDoctestFailures):
    failures = excinfo.value.failures
    if failures is not None:
    reprlocation_lines = []
    for failure in failures:
    example = failure.example
    test = failure.test
    filename = test.filename
    if test.lineno is None:
    lineno = None
    else:
    lineno = test.lineno + example.lineno + 1
    message = type(failure).__name__
    reprlocation = ReprFileLocation(filename, lineno, message)
    checker = _get_checker()
    report_choice = _get_report_choice(
    self.config.getoption("doctestreport")
    )
    if lineno is not None:
    lines = failure.test.docstring.splitlines(False)
    # add line numbers to the left of the error message
    lines = [
    "%03d %s" % (i + test.lineno + 1, x)
    for (i, x) in enumerate(lines)
    ]
    # trim docstring error lines to 10
    lines = lines[max(example.lineno - 9, 0) : example.lineno + 1]
    else:
    lines = [
    "EXAMPLE LOCATION UNKNOWN, not showing all tests of that example"
    ]
    indent = ">>>"
    for line in example.source.splitlines():
    lines.append("??? {} {}".format(indent, line))
    indent = "..."
    if isinstance(failure, doctest.DocTestFailure):
    lines += checker.output_difference(
    example, failure.got, report_choice
    ).split("\n")
    else:
    inner_excinfo = ExceptionInfo(failure.exc_info)
    lines += ["UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)]
    lines += traceback.format_exception(*failure.exc_info)
    reprlocation_lines.append((reprlocation, lines))
    return ReprFailDoctest(reprlocation_lines)
    ) - not really sure what though - but might be just as simple as "doctest failed" - currently it is empty, see test_doctest_id.

@blueyed blueyed force-pushed the summary-short_msg branch 2 times, most recently from 8aedb0b to 2a06e76 Compare October 19, 2019 03:14
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

I left some minor suggestions which I belive are simple and worth doing. 👍

[
"*test summary*",
"FAILED test_fail_extra_reporting.py::test_this - AssertionError: this_failedt...",
"FAILED test_fail_extra_reporting.py::test_linematcher - remains unmatched: 'l...",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@blueyed blueyed mentioned this pull request Oct 24, 2019
2 tasks
@blueyed
Copy link
Contributor Author

blueyed commented Oct 28, 2019

Incorporated feedback.

This is meant to improve the short msg with `-r`, where you want to see
the non-matched line, and not the first line (that might have matched),
from pytester's `_match_lines`.

This will also come in handy for a better `__repr__`.
blueyed added a commit to blueyed/pytest that referenced this pull request Nov 1, 2019
blueyed added a commit to blueyed/pytest that referenced this pull request Nov 1, 2019
Regressed in 000b906.

Adds / handles `short_msg` to / in `ReprFileLocation`.

Restores `test_pytest_fail` to before 53568a5, and hardens
`test_fail_extra_reporting`.

Ref: pytest-dev#6003
blueyed added a commit to blueyed/pytest that referenced this pull request Nov 1, 2019
Regressed in 000b906.

Adds / handles `short_msg` to / in `ReprFileLocation`.

Restores `test_pytest_fail` to before 53568a5, and hardens
`test_fail_extra_reporting`.

Ref: pytest-dev#6003
@blueyed
Copy link
Contributor Author

blueyed commented Nov 1, 2019

Updated in blueyed#44.
Closing for now, might come back to it later.

@blueyed blueyed closed this Nov 1, 2019
@blueyed blueyed deleted the summary-short_msg branch November 1, 2019 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants