diff --git a/src/_pytest/_io/saferepr.py b/src/_pytest/_io/saferepr.py index 07159e7b3..c1bb3ae8f 100644 --- a/src/_pytest/_io/saferepr.py +++ b/src/_pytest/_io/saferepr.py @@ -94,7 +94,9 @@ def safeformat(obj: object) -> str: DEFAULT_REPR_MAX_SIZE = 240 -def saferepr(obj: object, maxsize: Optional[int] = DEFAULT_REPR_MAX_SIZE, use_ascii: bool = False) -> str: +def saferepr( + obj: object, maxsize: Optional[int] = DEFAULT_REPR_MAX_SIZE, use_ascii: bool = False +) -> str: """Return a size-limited safe repr-string for the given object. Failing __repr__ functions of user instances will be represented diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index a854f7171..32ad03e78 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -157,11 +157,17 @@ def has_default_eq( return True -def assertrepr_compare(config, op: str, left: Any, right: Any, use_ascii: bool=False) -> Optional[List[str]]: +def assertrepr_compare( + config, op: str, left: Any, right: Any, use_ascii: bool = False +) -> Optional[List[str]]: """Return specialised explanations for some operators/operands.""" verbose = config.getoption("verbose") - use_ascii = isinstance(left, str) and isinstance(right, str) and normalize("NFD", left) == normalize("NFD", right) + use_ascii = ( + isinstance(left, str) + and isinstance(right, str) + and normalize("NFD", left) == normalize("NFD", right) + ) if verbose > 1: left_repr = saferepr_unlimited(left, use_ascii=use_ascii) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index d0f266769..e253144a2 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -781,7 +781,11 @@ class TestAssert_reprcompare: left = "hyv\xe4" right = "hyva\u0308" expl = callequal(left, right) - assert expl == ['"\'hyv\\\\xe4\'" == "\'hyva\\\\u0308\'"', f'- {str(right)}', f'+ {str(left)}'] + assert expl == [ + "\"'hyv\\\\xe4'\" == \"'hyva\\\\u0308'\"", + f"- {str(right)}", + f"+ {str(left)}", + ] class TestAssert_reprcompare_dataclass: