Skip to content

AssertionError message contains unnecessary newline characters in verbose mode #9742

Closed
@samuelcolvin

Description

@samuelcolvin
Member

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)

Activity

added 3 commits that reference this issue on Mar 8, 2022
35a0b9b
3c629dc
350ab6f
added
topic: reportingrelated to terminal output and user-facing messages and errors
on Mar 15, 2022
added a commit that references this issue on Mar 19, 2022
b75cbee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @samuelcolvin@Zac-HD

      Issue actions

        `AssertionError` message contains unnecessary newline characters in verbose mode · Issue #9742 · pytest-dev/pytest