Skip to content

Commit a664d40

Browse files
committed
Reverse / fix meaning of "+/-" in error diffs
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
1 parent 4038d6c commit a664d40

File tree

6 files changed

+453
-186
lines changed

6 files changed

+453
-186
lines changed

doc/en/example/reportingdemo.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Here is a nice run of several failures and how ``pytest`` presents things:
8181
def test_eq_text(self):
8282
> assert "spam" == "eggs"
8383
E AssertionError: assert 'spam' == 'eggs'
84-
E - spam
85-
E + eggs
84+
E - eggs
85+
E + spam
8686
8787
failure_demo.py:45: AssertionError
8888
_____________ TestSpecialisedExplanations.test_eq_similar_text _____________
@@ -92,9 +92,9 @@ Here is a nice run of several failures and how ``pytest`` presents things:
9292
def test_eq_similar_text(self):
9393
> assert "foo 1 bar" == "foo 2 bar"
9494
E AssertionError: assert 'foo 1 bar' == 'foo 2 bar'
95-
E - foo 1 bar
95+
E - foo 2 bar
9696
E ? ^
97-
E + foo 2 bar
97+
E + foo 1 bar
9898
E ? ^
9999
100100
failure_demo.py:48: AssertionError
@@ -106,8 +106,8 @@ Here is a nice run of several failures and how ``pytest`` presents things:
106106
> assert "foo\nspam\nbar" == "foo\neggs\nbar"
107107
E AssertionError: assert 'foo\nspam\nbar' == 'foo\neggs\nbar'
108108
E foo
109-
E - spam
110-
E + eggs
109+
E - eggs
110+
E + spam
111111
E bar
112112
113113
failure_demo.py:51: AssertionError
@@ -122,9 +122,9 @@ Here is a nice run of several failures and how ``pytest`` presents things:
122122
E AssertionError: assert '111111111111...2222222222222' == '111111111111...2222222222222'
123123
E Skipping 90 identical leading characters in diff, use -v to show
124124
E Skipping 91 identical trailing characters in diff, use -v to show
125-
E - 1111111111a222222222
125+
E - 1111111111b222222222
126126
E ? ^
127-
E + 1111111111b222222222
127+
E + 1111111111a222222222
128128
E ? ^
129129
130130
failure_demo.py:56: AssertionError

src/_pytest/assertion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,4 @@ def pytest_sessionfinish(session):
168168

169169

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

0 commit comments

Comments
 (0)