Skip to content

Assertion truncation: properly handle long lines #1954

@mattduck

Description

@mattduck

(I'm running on the features branch).

Hey @flub, thanks for running the sprint the other day. I had a thought earlier: long lines can break the assertion truncation code. This is because we're checking the length of all lines here, but after that we assume that there are at least 10 lines in the explanation list.

Previously the only consequence of this is that if you had a list with a small number of long lines, you could trigger a nonsensical message:

screen shot 2016-09-22 at 00 33 50

However, since 999e7c6 it causes an IndexError.

Example:

def test_github():
    a = 'a' * 1000
    b = 'b' * 1000
    assert a == b

Produces:

...
                # Truncate lines if required
                if (sum(len(p) for p in new_expl[1:]) > 80*8 and
                        item.config.option.verbose < 2 and
                        not _running_on_ci()):
                    show_max = 10
                    truncated_count = len(new_expl) - show_max
>                   new_expl[show_max - 1] += " ..."
E                   IndexError: list index out of range

I think we should add test cases for this situation to ensure that long lines are properly supported. I also think the truncation logic will be easier to read and maintain if we extract it into its own function.

I've started to work on it. Still WIP but I'm happy to continue with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions