Skip to content

Commit fb79fa7

Browse files
committed
Merge branch 'issue1553/diff-final-newline' of https://github.com/tomviner/pytest
2 parents 24179dc + 98adf20 commit fb79fa7

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@
2323
only ran once. Now a failure is raised. Fixes (`#460`_). Thanks to
2424
`@nikratio`_ for bug report, `@RedBeardCode`_ and `@tomviner`_ for PR.
2525

26+
* Create correct diff for strings ending with newlines. Fixes (`#1553`_).
27+
Thanks `@Vogtinator`_ for reporting. Thanks to `@RedBeardCode`_ and
28+
`@tomviner`_ for PR.
29+
30+
*
31+
2632
.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
2733
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
2834
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
2935
.. _#460: https://github.com/pytest-dev/pytest/pull/460
36+
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
3037

3138
.. _@graingert: https://github.com/graingert
3239
.. _@taschini: https://github.com/taschini
3340
.. _@nikratio: https://github.com/nikratio
3441
.. _@RedBeardCode: https://github.com/RedBeardCode
42+
.. _@Vogtinator: https://github.com/Vogtinator
3543

3644

3745
2.9.2

_pytest/assertion/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ def _diff_text(left, right, verbose=False):
225225
'characters in diff, use -v to show') % i]
226226
left = left[:-i]
227227
right = right[:-i]
228+
keepends = True
228229
explanation += [line.strip('\n')
229-
for line in ndiff(left.splitlines(),
230-
right.splitlines())]
230+
for line in ndiff(left.splitlines(keepends),
231+
right.splitlines(keepends))]
231232
return explanation
232233

233234

testing/test_assertion.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def test_long():
428428
"*- 3",
429429
"*- 5",
430430
"*- 7",
431-
"*truncated (191 more lines)*use*-vv*",
431+
"*truncated (193 more lines)*use*-vv*",
432432
])
433433

434434

@@ -626,3 +626,17 @@ def __hash__(self):
626626
+ repr(3)
627627
""").strip()
628628
assert '\n'.join(expl) == dedent
629+
630+
def test_diff_newline_at_end(monkeypatch, testdir):
631+
testdir.makepyfile(r"""
632+
def test_diff():
633+
assert 'asdf' == 'asdf\n'
634+
""")
635+
636+
result = testdir.runpytest()
637+
result.stdout.fnmatch_lines(r"""
638+
*assert 'asdf' == 'asdf\n'
639+
* - asdf
640+
* + asdf
641+
* ? +
642+
""")

0 commit comments

Comments
 (0)