From d8fa434d3980846acf8917325c49be5a85e4b5a1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 15 Jun 2019 10:18:44 -0300 Subject: [PATCH] Remove Python 2-only workaround --- src/_pytest/assertion/util.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index f2cb2ab63..762e5761d 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -244,17 +244,9 @@ def _compare_eq_iterable(left, right, verbose=0): # dynamic import to speedup pytest import difflib - try: - left_formatting = pprint.pformat(left).splitlines() - right_formatting = pprint.pformat(right).splitlines() - explanation = ["Full diff:"] - except Exception: - # hack: PrettyPrinter.pformat() in python 2 fails when formatting items that can't be sorted(), ie, calling - # sorted() on a list would raise. See issue #718. - # As a workaround, the full diff is generated by using the repr() string of each item of each container. - left_formatting = sorted(repr(x) for x in left) - right_formatting = sorted(repr(x) for x in right) - explanation = ["Full diff (fallback to calling repr on each item):"] + left_formatting = pprint.pformat(left).splitlines() + right_formatting = pprint.pformat(right).splitlines() + explanation = ["Full diff:"] explanation.extend( line.strip() for line in difflib.ndiff(left_formatting, right_formatting) )