Open altendky opened 4 years ago
No fix there in the PR but a test anyways in the suite.
I traced this down to a pprint.pformat()
call in _pytest._io.saferepr.safeformat()
. Passing width=99999
for example improves my case as does just using repr()
. I'm looking into existing tests related to this to see what the existing requirements are.
Python 3.8.2 (default, Mar 7 2020, 20:18:24)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pprint
>>> s26 = 's\n' * 26
>>> s27 = 's\n' * 27
>>> pprint.pformat(s26)
"'s\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\ns\\n'"
>>> pprint.pformat(s27)
"('s\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n'\n 's\\n')"
pprint.pformat()
sorts dicts, so repr() will not match present behavior (including failing a py35 test in CI due to lack of maintaining insertion order). pprint.pformat(obj, width=1000000)
won't match because then (of course...) pprint
won't wrap stuff (though this does pass CI).
So, one probably bad idea would be to special case strings. Or perhaps I'm looking at the wrong thing as the error and it's not that pprint
is bad here but rather that it's getting corrupted downstream such that it doesn't get presented as pprint
intended. Maybe related to the newline rewrites because of other pieces I forget the names of at the moment.
And of course the situation I really care about is PyCharm's diff link so I'll have to dig into what that actually supports.
Good:
Bad:
Difference: The strings being compared are one character longer in the bad case.
This came up while asserting equality of GitHub Actions config files (
str
s) in PyCharm and noting that it wasn't showing the handy<Click to see difference>
link (https://youtrack.jetbrains.com/issue/PY-42076). To be clear, the captures below were taken from a shell so as to avoid PyCharm messing things up. The PyCharm issue happens at larger lengths than this does.This issue was referred to in #6757 but that ticket seems focused on other aspects of the output.