MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _compare_eq_iterable

Function _compare_eq_iterable

src/_pytest/assertion/util.py:287–315  ·  view source on GitHub ↗
(
    left: Iterable[Any], right: Iterable[Any], verbose: int = 0
)

Source from the content-addressed store, hash-verified

285
286
287def _compare_eq_iterable(
288 left: Iterable[Any], right: Iterable[Any], verbose: int = 0
289) -> List[str]:
290 if not verbose and not running_on_ci():
291 return ["Use -v to get the full diff"]
292 # dynamic import to speedup pytest
293 import difflib
294
295 left_formatting = pprint.pformat(left).splitlines()
296 right_formatting = pprint.pformat(right).splitlines()
297
298 # Re-format for different output lengths.
299 lines_left = len(left_formatting)
300 lines_right = len(right_formatting)
301 if lines_left != lines_right:
302 left_formatting = _pformat_dispatch(left).splitlines()
303 right_formatting = _pformat_dispatch(right).splitlines()
304
305 if lines_left > 1 or lines_right > 1:
306 _surrounding_parens_on_own_lines(left_formatting)
307 _surrounding_parens_on_own_lines(right_formatting)
308
309 explanation = ["Full diff:"]
310 # "right" is the expected base against which we compare "left",
311 # see https://github.com/pytest-dev/pytest/issues/3333
312 explanation.extend(
313 line.rstrip() for line in difflib.ndiff(right_formatting, left_formatting)
314 )
315 return explanation
316
317
318def _compare_eq_sequence(

Callers 1

_compare_eq_anyFunction · 0.85

Calls 3

_pformat_dispatchFunction · 0.90
running_on_ciFunction · 0.85

Tested by

no test coverage detected