Skip to content

AssertionError message contains unnecessary newline characters in verbose mode #9742

Closed
@samuelcolvin

Description

@samuelcolvin

After #3962 the initial "AssertionError" line of error messages with -vv includes escaped newlines \n which makes the messages harder to read

Example:

import string


def test_foobar():
    a = {string.ascii_letters[i]: i for i in range(26)}
    b = a.copy()
    a.pop('g')
    assert a == b

running pytest -vv gives:

>       assert a == b
E       AssertionError: assert {'a': 0,\n 'b': 1,\n 'c': 2,\n 'd': 3,\n 'e': 4,\n 'f': 5,\n 'h': 7,\n 'i': 8,\n 'j': 9,\n 'k': 10,\n 'l': 11,\n 'm': 12,\n 'n': 13,\n 'o': 14,\n 'p': 15,\n 'q': 16,\n 'r': 17,\n 's': 18,\n 't': 19,\n 'u': 20,\n 'v': 21,\n 'w': 22,\n 'x': 23,\n 'y': 24,\n 'z': 25} == {'a': 0,\n 'b': 1,\n 'c': 2,\n 'd': 3,\n 'e': 4,\n 'f': 5,\n 'g': 6,\n 'h': 7,\n 'i': 8,\n 'j': 9,\n 'k': 10,\n 'l': 11,\n 'm': 12,\n 'n': 13,\n 'o': 14,\n 'p': 15,\n 'q': 16,\n 'r': 17,\n 's': 18,\n 't': 19,\n 'u': 20,\n 'v': 21,\n 'w': 22,\n 'x': 23,\n 'y': 24,\n 'z': 25}
E         Common items:
...

Clearly the many \ns in the E AssertionError... line do not help explain the error.

I will create a fix for this and see if it's accepted:

OS: Macos, Ubuntu, all
pytest: pytest 6.2.5 (and any recent version of pytest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions