You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a quick hack that extends _diff_text the same way other diffing functions were in fbe3e29:
diff --git i/src/_pytest/assertion/util.py w/src/_pytest/assertion/util.py
index 3fe7eb9d8..9a7c6da72 100644
--- i/src/_pytest/assertion/util.py+++ w/src/_pytest/assertion/util.py@@ -242,7 +242,7 @@ def _compare_eq_any(
) -> list[str]:
explanation = []
if istext(left) and istext(right):
- explanation = _diff_text(left, right, verbose)+ explanation = _diff_text(left, right, highlighter, verbose)
else:
from _pytest.python_api import ApproxBase
@@ -274,7 +274,9 @@ def _compare_eq_any(
return explanation
-def _diff_text(left: str, right: str, verbose: int = 0) -> list[str]:+def _diff_text(+ left: str, right: str, highlighter: _HighlightFunc, verbose: int = 0+) -> list[str]:
"""Return the explanation for the diff between text.
Unless --verbose is used this will skip leading and trailing
@@ -315,10 +317,15 @@ def _diff_text(left: str, right: str, verbose: int = 0) -> list[str]:
explanation += ["Strings contain only whitespace, escaping them using repr()"]
# "right" is the expected base against which we compare "left",
# see https://github.com/pytest-dev/pytest/issues/3333
- explanation += [- line.strip("\n")- for line in ndiff(right.splitlines(keepends), left.splitlines(keepends))- ]+ explanation.extend(+ highlighter(+ "\n".join(+ line.strip("\n")+ for line in ndiff(right.splitlines(keepends), left.splitlines(keepends))+ ),+ lexer="diff",+ ).splitlines()+ )
return explanation
and from a quick test, that seems to help:
@BenjaminSchubert was there a reason you didn't do _diff_text as part of #11530 as well, or was that just an oversight perhaps?
Warning
it is CRITICAL that
pygments
is installed, otherwise the diff won't be colored at allthis is a secret undocumented feature, see: #13174
here we can observe that no coloring has been applied to the string diff
pip list
from the virtual environment you are usingwindows 10
The text was updated successfully, but these errors were encountered: