Currently, when a dictionary comparison fails with TestCase.assertDictEqual()
between a dict
and OrderedDict
it just barfs out both dictionaries:
TestCase().assertDictEqual(dict(a=1,b=2,c=3), OrderedDict(a=1,b=3,c=3))
Traceback (most recent call last):
File "/usr/local/lib/python3.10/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "/usr/local/lib/python3.10/unittest/case.py", line 1144, in assertDictEqual
self.fail(self._formatMessage(msg, standardMsg))
File "/usr/local/lib/python3.10/unittest/case.py", line 675, in fail
raise self.failureException(msg)
AssertionError: {'a': 1, 'b': 2, 'c': 3} != OrderedDict([('a', 1), ('b', 3), ('c', 3)])
- {'a': 1, 'b': 2, 'c': 3}
+ OrderedDict([('a', 1), ('b', 3), ('c', 3)])
Instead of the prettier dict
/dict
comparison:
TestCase().assertDictEqual(dict(a=1,b=2,c=3), dict(a=1,b=3,c=3))
Traceback (most recent call last):
File "/usr/local/lib/python3.10/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "/usr/local/lib/python3.10/unittest/case.py", line 1144, in assertDictEqual
self.fail(self._formatMessage(msg, standardMsg))
File "/usr/local/lib/python3.10/unittest/case.py", line 675, in fail
raise self.failureException(msg)
AssertionError: {'a': 1, 'b': 2, 'c': 3} != {'a': 1, 'b': 3, 'c': 3}
- {'a': 1, 'b': 2, 'c': 3}
? ^
+ {'a': 1, 'b': 3, 'c': 3}
? ^
I’m aware that I could just cast it by using dict(my_ordered_dict)
, but considering OrderedDict
is treated exactly the same as a regular dict
99% of the time this feels like unexpected behavior. Plus, if there is a nested OrderedDict
I would have to cast it recursively or use the clunky json.loads(json.dumps(my_ordered_dict))
which may or may not support the types present in the object.
Please let me know if this is intended behavior.