Skip to content

Feature Req: Improve Short Error Reports for Exceptions #199

@JWCS

Description

@JWCS

Re: #198 , Thanks for the quick fix!
I've tested it out, and with every check context, I'm able to catch the default assert, or whatever else exception is raised, and carry on with the rest of the checks.

But I tried to intentionally fail multiple, and after the first failure msg, there's no line number, just the exception message.
I know (README) that pseudo tracebacks stop after the first (and a la --check-max-tb=5), but usually the shortened FAILURE lines are indicative of where they failed (variable names, specifically used values, etc).

The current format of (normal) short one-line failure msgs are FAILURE: check <repr of args / src line>: <included msg if any> .
But for with check: list()[-1], it's only FAILURE: list index out of range, having no real info about which source line in question broke.

For these raised asserts, could they be shown something like FAILURE: <source line>: <Exception Type + Exception Msg> ?

# test_multi_check_raises.py
def test_multi_check_raises(check):
    lst_1 = []
    with check:
        assert lst_1["N/A"] == "Fail 1"
    with check:
        assert lst_1[-1] == "Fail 2"
    lst_2 = ["Success"]
    lst_3 = []
    with check:
        assert lst_2[-1] == "Success"
    with check:
        assert lst_3[-1] == "Success"
plugins: check-2.8.0, cov-7.0.0, fast-first-1.0.5, loguru-0.4.0, skip-slow-0.0.5, sugar-1.1.1, syrupy-5.1.0, anyio-4.12.1, Faker-40.5.1
collected 1 item
――――――――――――――――――― test_multi_check_raises ――――――――――――――――

FAILURE: list indices must be integers or slices, not str
tests/test_multi_check_raises.py:4 in test_multi_check_raises() -> with check:
test_multi_check_raises.py:5 in test_multi_check_raises -> assert lst_1["N/A"] == "Fail 1"
TypeError: list indices must be integers or slices, not str


FAILURE: list index out of range
FAILURE: list index out of range
------------------------------------------------------------
Failed Checks: 3

 tests/test_multi_check_raises.py::test_multi_check_raises ⨯                             100% ██████████
========================= short test summary info ==========================
FAILED tests/test_multi_check_raises.py::test_multi_check_raises - list indices must be integers or slices, not str

Results (0.11s):
       1 failed
         - tests/test_multi_check_raises.py:2 test_multi_check_raises

A la hypothetical

FAILURE: list indices must be integers or slices, not str
tests/test_multi_check_raises.py:4 in test_multi_check_raises() -> with check:
test_multi_check_raises.py:5 in test_multi_check_raises -> assert lst_1["N/A"] == "Fail 1"
TypeError: list indices must be integers or slices, not str


FAILURE: assert lst_1[-1] == "Fail 2": IndexError list index out of range
FAILURE: assert lst_3[-1] == "Success": IndexError list index out of range
------------------------------------------------------------
Failed Checks: 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions