From ccfb6691dfcf38dd76c3eb2e1276b87c37977559 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Mon, 27 Nov 2023 13:55:46 +0000 Subject: [PATCH] Re-print the ordered dict as a normal dict --- src/_pytest/_io/pprint.py | 2 +- testing/io/test_pprint.py | 37 +++++++++++-------------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/_pytest/_io/pprint.py b/src/_pytest/_io/pprint.py index e922d7156..bb59253f7 100644 --- a/src/_pytest/_io/pprint.py +++ b/src/_pytest/_io/pprint.py @@ -178,7 +178,7 @@ class PrettyPrinter: return cls = object.__class__ stream.write(cls.__name__ + "(") - self._format(list(object.items()), stream, indent, allowance, context, level) + self._pprint_dict(object, stream, indent, allowance, context, level) stream.write(")") _dispatch[_collections.OrderedDict.__repr__] = _pprint_ordered_dict diff --git a/testing/io/test_pprint.py b/testing/io/test_pprint.py index 3ed601972..3432c63f6 100644 --- a/testing/io/test_pprint.py +++ b/testing/io/test_pprint.py @@ -84,28 +84,19 @@ class DataclassWithTwoItems: pytest.param( OrderedDict({"one": 1}), """ - OrderedDict([ - ( - 'one', - 1, - ), - ]) + OrderedDict({ + 'one': 1, + }) """, id="ordereddict-one-item", ), pytest.param( OrderedDict({"one": 1, "two": 2}), """ - OrderedDict([ - ( - 'one', - 1, - ), - ( - 'two', - 2, - ), - ]) + OrderedDict({ + 'one': 1, + 'two': 2, + }) """, id="ordereddict-two-items", ), @@ -389,16 +380,10 @@ class DataclassWithTwoItems: 'one': 1, 'two': 2, }), - 'ordereddict': OrderedDict([ - ( - 'one', - 1, - ), - ( - 'two', - 2, - ), - ]), + 'ordereddict': OrderedDict({ + 'one': 1, + 'two': 2, + }), 'set': { 1, 2,