Skip to content

[WIP] Correct weird output in long string assertions #7136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_pytest/_io/saferepr.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def safeformat(obj: Any) -> str:
with a short exception info.
"""
try:
return pprint.pformat(obj)
return pprint.pformat(obj, width=1000000)
except Exception as exc:
return _format_repr_exception(exc, obj)

Expand Down
26 changes: 26 additions & 0 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,32 @@ 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(
Expand Down