From 98adf204b2fbdbeb696b47c4bf6abecad80da1d0 Mon Sep 17 00:00:00 2001 From: Tom Viner Date: Tue, 21 Jun 2016 16:48:29 +0200 Subject: [PATCH 1/3] issue 1553: Include terminal newlines in diffs --- CHANGELOG.rst | 8 ++++++++ _pytest/assertion/util.py | 5 +++-- testing/test_assertion.py | 16 +++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0a71de6b9..cb6bd625a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -23,15 +23,23 @@ only ran once. Now a failure is raised. Fixes (`#460`_). Thanks to `@nikratio`_ for bug report, `@RedBeardCode`_ and `@tomviner`_ for PR. +* 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 .. _#460: https://github.com/pytest-dev/pytest/pull/460 +.. _#1553: https://github.com/pytest-dev/pytest/issues/1553 .. _@graingert: https://github.com/graingert .. _@taschini: https://github.com/taschini .. _@nikratio: https://github.com/nikratio .. _@RedBeardCode: https://github.com/RedBeardCode +.. _@Vogtinator: https://github.com/Vogtinator 2.9.2 diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index f2f23efea..8bf425caf 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -225,9 +225,10 @@ def _diff_text(left, right, verbose=False): 'characters in diff, use -v to show') % i] left = left[:-i] right = right[:-i] + keepends = True explanation += [line.strip('\n') - for line in ndiff(left.splitlines(), - right.splitlines())] + for line in ndiff(left.splitlines(keepends), + right.splitlines(keepends))] return explanation diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 347278e19..dfa1b9420 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -428,7 +428,7 @@ def test_assert_compare_truncate_longmessage(monkeypatch, testdir): "*- 3", "*- 5", "*- 7", - "*truncated (191 more lines)*use*-vv*", + "*truncated (193 more lines)*use*-vv*", ]) @@ -626,3 +626,17 @@ def test_set_with_unsortable_elements(): + 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 + * ? + + """) From 7d87a1b127249d6051066a5ff0197a10c5505224 Mon Sep 17 00:00:00 2001 From: Oliver Bestwalter Date: Tue, 21 Jun 2016 20:10:22 +0200 Subject: [PATCH 2/3] Add test for failing assertion Should contain function name that caused the failure (see pull request #1631). --- testing/python/fixture.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testing/python/fixture.py b/testing/python/fixture.py index d6e3250d0..85de0c318 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -490,6 +490,20 @@ class TestRequestBasic: print(ss.stack) assert teardownlist == [1] + def test_mark_as_fixture_with_prefix_and_decorator_fails(self, testdir): + testdir.makeconftest(""" + import pytest + + @pytest.fixture + def pytest_funcarg__marked_with_prefix_and_decorator(): + pass + """) + result = testdir.runpytest_subprocess() + assert result.ret != 0 + result.stdout.fnmatch_lines([ + "*AssertionError:*pytest_funcarg__marked_with_prefix_and_decorator*" + ]) + def test_request_addfinalizer_failing_setup(self, testdir): testdir.makepyfile(""" import pytest From be1dabd6a9ac65a0badb93edaedb1da4ef700c4d Mon Sep 17 00:00:00 2001 From: HEAD KANGAROO Date: Wed, 22 Jun 2016 13:43:11 +0100 Subject: [PATCH 3/3] cache.rst: Fix wrong command used The "Inspecting Cache content" section was showing --cache-clear command, but should actually be using --cache-show command. Also; update AUTHORS --- AUTHORS | 1 + doc/en/cache.rst | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 3e079b522..c35e66587 100644 --- a/AUTHORS +++ b/AUTHORS @@ -22,6 +22,7 @@ Bruno Oliveira Cal Leeming Carl Friedrich Bolz Charles Cloud +Charnjit SiNGH (CCSJ) Chris Lamb Christian Theunert Christian Tismer diff --git a/doc/en/cache.rst b/doc/en/cache.rst index de03204de..860b13753 100644 --- a/doc/en/cache.rst +++ b/doc/en/cache.rst @@ -222,9 +222,9 @@ Inspecting Cache content ------------------------------- You can always peek at the content of the cache using the -``--cache-clear`` command line option:: +``--cache-show`` command line option:: - $ py.test --cache-clear + $ py.test --cache-show ======= test session starts ======== platform linux -- Python 3.5.1, pytest-2.9.2, py-1.4.31, pluggy-0.3.1 rootdir: $REGENDOC_TMPDIR, inifile: