From 1c81bd926d7f00b15e86e8e79d8306d2ed6a89c1 Mon Sep 17 00:00:00 2001 From: rootile Date: Thu, 14 May 2026 14:30:06 +0200 Subject: [PATCH] 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 --- tests/functional2/conftest.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/functional2/conftest.py b/tests/functional2/conftest.py index da0cc29f2..678ec7c5b 100644 --- a/tests/functional2/conftest.py +++ b/tests/functional2/conftest.py @@ -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.