Skip to content

Question: Line breaks in test output #534

@jakubbortlik

Description

@jakubbortlik

Hi and thanks for your great plugin!

I'd like to ask about the behaviour of the test output - it always seems to break long output lines onto separate lines (i.e., insert \n characters). In my experience, this frequently makes the analysis of test output rather difficult, e.g., it's not straightforward to copy the test output to a separate buffer and reformat, e.g., when comparing two dictionaries.

Take this example:

def test_equality() -> None:
    """Showcase error output."""
    a = {
        "some_very_long_dictionary_key": "some_very_long_value",
        "another_very_very_very_long_dictionary_key": "some_other_very_long_value",
        "yet_another_very_very_very_long_dictionary_key": "some_other_very_long_value",
    }
    b = {
        "some_very_long_dictionary_key": "some_very_long_value",
        "another_very_very_very_long_dictionary_kee": "some_other_very_long_value",
        "yet_another_very_very_very_long_dictionary_key": "some_other_very_long_value",
    }
    assert a == b

The output can look something like this:

test_output.py:13: in test_equality
    assert a == b
E   AssertionError: assert {'some_very_long_dictionary_key': 'some_very_long_value', 'another_very_very_very_long_dictionary_key': 'some_other_very_long_value', 'yet_another_very_very_very_long_dictionary_key': 'some_other_very_long_value'} == {'some_very_long_dictionary_key': 'some_very_long_value', 'another_ver
y_very_very_long_dictionary_kee': 'some_other_very_long_value', 'yet_another_very_very_very_long_dictionary_key': 'some_other_very_long_value'}
E     Common items:
E     {'some_very_long_dictionary_key': 'some_very_long_value',
E      'yet_another_very_very_very_long_dictionary_key': 'some_other_very_long_value'}
E     Left contains 1 more item:
E     {'another_very_very_very_long_dictionary_key': 'some_other_very_long_value'}
E     Right contains 1 more item:
E     {'another_very_very_very_long_dictionary_kee': 'some_other_very_long_value'}
E     Full diff:
E       {
E     -  'another_very_very_very_long_dictionary_kee': 'some_other_very_long_value',
E     ?                                            ^
E     +  'another_very_very_very_long_dictionary_key': 'some_other_very_long_value',
E     ?                                            ^
E        'some_very_long_dictionary_key': 'some_very_long_value',
E        'yet_another_very_very_very_long_dictionary_key': 'some_other_very_long_value',
E       }

While the difference is highlighted with the ^ characters, and in this trivial case it's quite easy to see the difference, quite often I'd like to just copy the "line" with the AssertionError and reformat and :diffthis the two differing elements. The inserted new line characters make it unnecessarily difficult.

Is it possible to somehow configure the behaviour so that new lines are not inserted in the output? I've just now noticed that the contents of the buffer reorganized when I resize the window, so I guess it could be possible to modify the behaviour somethow.

I see that the concatenation happens here, and I naively tried to replace the \n with the empty string, but that unsurprisingly didn't work.

I'd be glad for any suggestions on how to deal with this.

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