Skip to content

Commit

Permalink
Reverse / fix meaning of "+/-" in error diffs
Browse files Browse the repository at this point in the history
The convention is "assert result is expected".  Pytest's error diffs now
reflect this. "-" means that sth. expected is missing in the result and
"+" means that there are unexpected extras in the result.

Fixes: #3333
  • Loading branch information
sscherfke committed Feb 4, 2020
1 parent 4038d6c commit a664d40
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 186 deletions.
16 changes: 8 additions & 8 deletions doc/en/example/reportingdemo.rst
Expand Up @@ -81,8 +81,8 @@ Here is a nice run of several failures and how ``pytest`` presents things:
def test_eq_text(self):
> assert "spam" == "eggs"
E AssertionError: assert 'spam' == 'eggs'
E - spam
E + eggs
E - eggs
E + spam
failure_demo.py:45: AssertionError
_____________ TestSpecialisedExplanations.test_eq_similar_text _____________
Expand All @@ -92,9 +92,9 @@ Here is a nice run of several failures and how ``pytest`` presents things:
def test_eq_similar_text(self):
> assert "foo 1 bar" == "foo 2 bar"
E AssertionError: assert 'foo 1 bar' == 'foo 2 bar'
E - foo 1 bar
E - foo 2 bar
E ? ^
E + foo 2 bar
E + foo 1 bar
E ? ^
failure_demo.py:48: AssertionError
Expand All @@ -106,8 +106,8 @@ Here is a nice run of several failures and how ``pytest`` presents things:
> assert "foo\nspam\nbar" == "foo\neggs\nbar"
E AssertionError: assert 'foo\nspam\nbar' == 'foo\neggs\nbar'
E foo
E - spam
E + eggs
E - eggs
E + spam
E bar
failure_demo.py:51: AssertionError
Expand All @@ -122,9 +122,9 @@ Here is a nice run of several failures and how ``pytest`` presents things:
E AssertionError: assert '111111111111...2222222222222' == '111111111111...2222222222222'
E Skipping 90 identical leading characters in diff, use -v to show
E Skipping 91 identical trailing characters in diff, use -v to show
E - 1111111111a222222222
E - 1111111111b222222222
E ? ^
E + 1111111111b222222222
E + 1111111111a222222222
E ? ^
failure_demo.py:56: AssertionError
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/assertion/__init__.py
Expand Up @@ -168,4 +168,4 @@ def pytest_sessionfinish(session):


def pytest_assertrepr_compare(config, op, left, right):
return util.assertrepr_compare(config=config, op=op, left=left, right=right)
return util.assertrepr_compare(config=config, op=op, result=left, expected=right)

0 comments on commit a664d40

Please sign in to comment.