From b7a89690c7a9dc3d651802151dc332a35aec3325 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Wed, 29 Apr 2020 22:28:15 -0400 Subject: [PATCH 1/6] Test for more than 52...? not creating garbage --- testing/test_assertion.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 042aa705502..ddb791e256a 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1043,6 +1043,31 @@ def test_many_lines(): result = testdir.runpytest() result.stdout.fnmatch_lines(["* 6*"]) + @pytest.mark.parametrize( + argnames=['n'], + argvalues=[[26], [27]], + ) + def test_more_than_52_not_garbage(self, n, monkeypatch, testdir): + a = 'a\n' * n + b = 'b\n' * n + + testdir.makepyfile( + r""" + def test_many_lines(): + a = {a!r} + b = {b!r} + assert a == b + """.format(a=a, b=b) + ) + monkeypatch.delenv("CI", raising=False) + + result = testdir.runpytest('-vv') + + assert any( + "AssertionError: assert {a!r} == {b!r}".format(a=a, b=b) in line + for line in result.outlines + ) + def test_python25_compile_issue257(testdir): testdir.makepyfile( From 145c8744046e655f09d0aa70281027822f94e83d Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Thu, 30 Apr 2020 21:24:50 -0400 Subject: [PATCH 2/6] try using repr() for safeformat() --- src/_pytest/_io/saferepr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/_io/saferepr.py b/src/_pytest/_io/saferepr.py index 23af4d0bb70..dae606d9782 100644 --- a/src/_pytest/_io/saferepr.py +++ b/src/_pytest/_io/saferepr.py @@ -67,7 +67,7 @@ def safeformat(obj: Any) -> str: with a short exception info. """ try: - return pprint.pformat(obj) + return repr(obj) except Exception as exc: return _format_repr_exception(exc, obj) From a7c096e795205c7a51a7836762fac82c5c28fa6c Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Thu, 30 Apr 2020 21:39:54 -0400 Subject: [PATCH 3/6] try using pprint.pformat(width=1_000_000) for safeformat() --- src/_pytest/_io/saferepr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/_io/saferepr.py b/src/_pytest/_io/saferepr.py index dae606d9782..22877ce2937 100644 --- a/src/_pytest/_io/saferepr.py +++ b/src/_pytest/_io/saferepr.py @@ -67,7 +67,7 @@ def safeformat(obj: Any) -> str: with a short exception info. """ try: - return repr(obj) + return pprint.pformat(obj, width=1_000_000) except Exception as exc: return _format_repr_exception(exc, obj) From 757da42fca393fa5189370f6462bebc465050b77 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Thu, 30 Apr 2020 21:42:04 -0400 Subject: [PATCH 4/6] try using pprint.pformat(width=1000000) for safeformat() --- src/_pytest/_io/saferepr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/_io/saferepr.py b/src/_pytest/_io/saferepr.py index 22877ce2937..898e28c07b1 100644 --- a/src/_pytest/_io/saferepr.py +++ b/src/_pytest/_io/saferepr.py @@ -67,7 +67,7 @@ def safeformat(obj: Any) -> str: with a short exception info. """ try: - return pprint.pformat(obj, width=1_000_000) + return pprint.pformat(obj, width=1000000) except Exception as exc: return _format_repr_exception(exc, obj) From fbda78a45640203e3bc65b2268cdbefe09e42127 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Thu, 30 Apr 2020 21:46:19 -0400 Subject: [PATCH 5/6] black --- testing/test_assertion.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index ddb791e256a..56a4af03e46 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1044,12 +1044,12 @@ def test_many_lines(): result.stdout.fnmatch_lines(["* 6*"]) @pytest.mark.parametrize( - argnames=['n'], + argnames=["n"], argvalues=[[26], [27]], ) def test_more_than_52_not_garbage(self, n, monkeypatch, testdir): - a = 'a\n' * n - b = 'b\n' * n + a = "a\n" * n + b = "b\n" * n testdir.makepyfile( r""" @@ -1057,11 +1057,13 @@ def test_many_lines(): a = {a!r} b = {b!r} assert a == b - """.format(a=a, b=b) + """.format( + a=a, b=b + ) ) monkeypatch.delenv("CI", raising=False) - result = testdir.runpytest('-vv') + result = testdir.runpytest("-vv") assert any( "AssertionError: assert {a!r} == {b!r}".format(a=a, b=b) in line From 8c2c954ffb6b7d9a161610de11e2b450bc02e7d3 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Thu, 30 Apr 2020 21:49:35 -0400 Subject: [PATCH 6/6] black --- testing/test_assertion.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 56a4af03e46..d1ecf6a409f 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1044,8 +1044,7 @@ def test_many_lines(): result.stdout.fnmatch_lines(["* 6*"]) @pytest.mark.parametrize( - argnames=["n"], - argvalues=[[26], [27]], + argnames=["n"], argvalues=[[26], [27]], ) def test_more_than_52_not_garbage(self, n, monkeypatch, testdir): a = "a\n" * n