Skip to content

Commit

Permalink
issue 1553: Include terminal newlines in diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomviner committed Jun 21, 2016
1 parent 5d8d1db commit b13a046
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@
is specified on the command line together with the ``--pyargs``
option. Thanks to `@taschini`_ for the PR (`#1597`_).

* Create correct diff for strings ending with newlines. Fixes (`#1553`_).
Thanks `@Vogtinator`_ for reporting. Thanks to `@RedBeardCode`_ and
`@tomviner`_ for PR.

*

.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553

.. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini
.. _@Vogtinator: https://github.com/Vogtinator


2.9.2
Expand Down
6 changes: 4 additions & 2 deletions _pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ def _diff_text(left, right, verbose=False):
'characters in diff, use -v to show') % i]
left = left[:-i]
right = right[:-i]
# We set splitlines' keepends=True, which can only be passed as a
# positional argument
explanation += [line.strip('\n')
for line in ndiff(left.splitlines(),
right.splitlines())]
for line in ndiff(left.splitlines(True),
right.splitlines(True))]
return explanation


Expand Down
16 changes: 15 additions & 1 deletion testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def test_long():
"*- 3",
"*- 5",
"*- 7",
"*truncated (191 more lines)*use*-vv*",
"*truncated (193 more lines)*use*-vv*",
])


Expand Down Expand Up @@ -626,3 +626,17 @@ def __hash__(self):
+ repr(3)
""").strip()
assert '\n'.join(expl) == dedent

def test_diff_newline_at_end(monkeypatch, testdir):
testdir.makepyfile(r"""
def test_diff():
assert 'asdf' == 'asdf\n'
""")

result = testdir.runpytest()
result.stdout.fnmatch_lines(r"""
*assert 'asdf' == 'asdf\n'
* - asdf
* + asdf
* ? +
""")

0 comments on commit b13a046

Please sign in to comment.