Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions src/_pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections.abc import Callable
from collections.abc import Iterator
from collections.abc import Sequence
from collections.abc import Set as AbstractSet
from typing import Literal
from unicodedata import normalize

Expand All @@ -15,8 +16,6 @@
from _pytest._io.saferepr import saferepr_unlimited
from _pytest.assertion._compare_any import _compare_eq_any
from _pytest.assertion._compare_set import SET_COMPARISON_FUNCTIONS
from _pytest.assertion._guards import isset
from _pytest.assertion._guards import istext
from _pytest.assertion._typing import _AssertionTextDiffStyle
from _pytest.assertion._typing import _HighlightFunc
from _pytest.assertion._typing import NO_TRUNCATION_BUDGET
Expand Down Expand Up @@ -179,21 +178,26 @@ def assertrepr_compare(
summary = f"{left_repr} {op} {right_repr}"

try:
if op == "==":
source = _compare_eq_any(
left,
right,
highlighter,
verbose,
assertion_text_diff_style,
truncation_budget,
)
elif op == "not in" and istext(left) and istext(right):
source = _notin_text(left, right, verbose, truncation_budget)
elif op in {"!=", ">=", "<=", ">", "<"} and isset(left) and isset(right):
source = SET_COMPARISON_FUNCTIONS[op](left, right, highlighter, verbose)
else:
source = iter(())
match (left, op, right):
case (_, "==", _):
source = _compare_eq_any(
left,
right,
highlighter,
verbose,
assertion_text_diff_style,
truncation_budget,
)
case (str(), "not in", str()):
source = _notin_text(left, right, verbose, truncation_budget)
case (
AbstractSet(),
"!=" | ">=" | "<=" | ">" | "<",
AbstractSet(),
):
source = SET_COMPARISON_FUNCTIONS[op](left, right, highlighter, verbose)
case _:
source = iter(())

# Only yield the summary if there is a detailed explanation.
# Make sure there's a separating empty line after the summary.
Expand Down