Skip to content

Please document the meaning of - and + in the output of failed string-equality assertions #3721

@offby1

Description

@offby1

I'm using pytest-3.6.3

I realized that that when I am looking at the output of a failed string-equality assertion, I didn't know what the - and the + meant. Here's an example that I created once I deduced their meanings:

def test_wat_plus():
    # This failure's output includes a +, since the right-hand side has more stuff.
    assert 'one\ntwo\nthree\n' == 'one\ntwo\ntwo-anna-half\nthree\n'


def test_wat_minus():
    # This failure's output includes a -, since the left-hand side has more stuff.
    assert 'one\ntwo\ntwo-anna-half\nthree\n' == 'one\ntwo\nthree\n'

Running pytest yields this output:

python3 -m pytest test_wat.py 
=============================================================================================================== test session starts ================================================================================================================
platform darwin -- Python 3.7.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /private/tmp, inifile:
collected 2 items                                                                                                                                                                                                                                  

test_wat.py FF                                                                                                                                                                                                                               [100%]

===================================================================================================================== FAILURES =====================================================================================================================
__________________________________________________________________________________________________________________ test_wat_plus ___________________________________________________________________________________________________________________

    def test_wat_plus():
        # This failure's output includes a +, since the right-hand side has more stuff.
>       assert 'one\ntwo\nthree\n' == 'one\ntwo\ntwo-anna-half\nthree\n'
E       AssertionError: assert 'one\ntwo\nthree\n' == 'one\ntwo\ntwo-anna-half\nthree\n'
E           one
E           two
E         + two-anna-half
E           three

test_wat.py:3: AssertionError
__________________________________________________________________________________________________________________ test_wat_minus __________________________________________________________________________________________________________________

    def test_wat_minus():
        # This failure's output includes a -, since the left-hand side has more stuff.
>       assert 'one\ntwo\ntwo-anna-half\nthree\n' == 'one\ntwo\nthree\n'
E       AssertionError: assert 'one\ntwo\ntw...half\nthree\n' == 'one\ntwo\nthree\n'
E           one
E           two
E         - two-anna-half
E           three

test_wat.py:8: AssertionError
============================================================================================================= 2 failed in 0.18 seconds =============================================================================================================

pytest itself is working fine; my complaint is that I had to write up this little example to be certain that - and + meant what I thought they meant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: docsdocumentation improvement, missing or needing clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions