Remove newlines from left/right operands with '-vv'#9743
Conversation
for more information, see https://pre-commit.ci
|
Thanks @samuelcolvin - this looks good to me, though I'll leave merging to another maintainer to be sure 🙂 |
|
Here's the output of And here's the output of this PR: So clearly an improvement! 👍 |
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks @samuelcolvin, appreciate a lot the PR! Very clean work. 👍
| if verbose > 1: | ||
| left_repr = safeformat(left) | ||
| right_repr = safeformat(right) | ||
| left_repr = saferepr_unlimited(left) |
There was a problem hiding this comment.
Indeed using safeformat for the left and right operands when verbose > 1 is not what is expected, because safeformat introduces newlines, and the result of assertrepr_compare is expected to be a list of lines; the string produced by safeformat (containing \n) is put as a single string in the result, which causes them to be escaped by the terminal later (I assume).
So the fix is entirely correct: use repr to produce the representation without \n, which is used to build the summary variable which is expected to be a single line.
AssertionError messageThe left/right operands produced when `verbose > 1` should not contain newlines, because they are used to build the `summary` string. The `assertrepr_compare` function returns a list of lines, and the summary is one of those lines and should not contain newlines itself. Fix pytest-dev#9742 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
The left/right operands produced when `verbose > 1` should not contain newlines, because they are used to build the `summary` string. The `assertrepr_compare` function returns a list of lines, and the summary is one of those lines and should not contain newlines itself. Fix pytest-dev#9742 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
fix #9742
I've done this in the least intrusive way possible, a cleaner solution would be to alter
safereprto behave like the newsaferepr_unlimitedmethod whenmaxsize=None, but that might effect some other code (though I think use ofsaferepr()withmaxsize=Noneis very rare).