_pytest.assertion.util module

Utilities for assertion debugging

format_explanation(explanation: str)str[source]

This formats an explanation

Normally all embedded newlines are escaped, however there are three exceptions:

{, } and ~. The first two are intended

cover nested explanations, see function and attribute explanations for examples (.visit_Call(), visit_Attribute()). The last one is for when one explanation needs to span multiple lines, e.g. when displaying diffs.

_split_explanation(explanation: str) → List[str][source]

Return a list of individual lines in the explanation

This will return a list of lines split on ‘

{‘, ‘ }’ and ‘ ~’.

Any other newlines will be escaped and appear in the line as the literal ‘

‘ characters.

_format_lines(lines: Sequence[str]) → List[str][source]

Format the individual lines

This will replace the ‘{‘, ‘}’ and ‘~’ characters of our mini formatting language with the proper ‘where …’, ‘and …’ and ‘ + …’ text, taking care of indentation along the way.

Return a list of formatted lines.

issequence(x: Any)bool[source]
istext(x: Any)bool[source]
isdict(x: Any)bool[source]
isset(x: Any)bool[source]
isdatacls(obj: Any)bool[source]
isattrs(obj: Any)bool[source]
isiterable(obj: Any)bool[source]
_gets_full_diff(op: str, left: Any, right: Any, verbose: int)bool[source]
assertrepr_compare(config, op: str, left: Any, right: Any) → Optional[List[str]][source]

Return specialised explanations for some operators/operands

_diff_text(left: str, right: str, verbose: int = 0) → List[str][source]

Return the explanation for the diff between text.

Unless –verbose is used this will skip leading and trailing characters which are identical to keep the diff minimal.

_compare_eq_verbose(left: Any, right: Any) → List[str][source]
_surrounding_parens_on_own_lines(lines: List[str])None[source]

Move opening/closing parenthesis/bracket to own lines.

_compare_eq_iterable(left: Iterable[Any], right: Iterable[Any], verbose: int = 0) → List[str][source]
_compare_eq_sequence(left: Sequence[Any], right: Sequence[Any], verbose: int = 0) → List[str][source]
_compare_eq_set(left: AbstractSet[Any], right: AbstractSet[Any], verbose: int = 0) → List[str][source]
_compare_eq_dict(left: Mapping[Any, Any], right: Mapping[Any, Any], verbose: int = 0) → List[str][source]
_compare_eq_cls(left: Any, right: Any, verbose: int, type_fns: Tuple[Callable[[Any], bool], Callable[[Any], bool]]) → List[str][source]
_notin_text(term: str, text: str, verbose: int = 0) → List[str][source]
_running_on_ci()[source]