tests/f2: improve error message for failed in assertions
By default, when one uses `in` assertions, upon failure newlines in any of the two strings is escaped, and everything is printed in a single line. This commit allows one to pass `-vv` to print out the left and righthand side unescaped, with each line of the output being its own line, improving readability a lot when dealing with multiline outputs. Change-Id: Iaf67a20fce57d375e2c62a8e8a0957b14eec26ef
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
pytest_plugins = (
|
||||
"testlib.fixtures.env",
|
||||
"testlib.fixtures.formatter",
|
||||
@@ -10,6 +12,28 @@ pytest_plugins = (
|
||||
"testlib.fixtures.pytest_command",
|
||||
)
|
||||
|
||||
|
||||
def pytest_assertrepr_compare(config: pytest.Config, op: str, left: object, right: object) -> list[str] | None:
|
||||
if not isinstance(left, str) or not isinstance(right, str) or op != "in":
|
||||
return None
|
||||
left: str
|
||||
right: str
|
||||
|
||||
expl = [
|
||||
f"{left} in {right}.",
|
||||
]
|
||||
|
||||
if config.get_verbosity():
|
||||
expl.append("left:")
|
||||
expl.extend([
|
||||
f" {line}" for line in left.splitlines()
|
||||
])
|
||||
expl.append("right:")
|
||||
expl.extend([
|
||||
f" {line}" for line in right.splitlines()
|
||||
])
|
||||
return expl
|
||||
|
||||
# the rest of this file is also a fork of pytest-tap v3.5 adjusted for lix use casess.
|
||||
# ideally this would be its own module, but xdist causes failures if it is. dunno why.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user