I'm writing a doctest for a function that outputs a dictionary. The doctest looks like
>>> my_function()
{'this': 'is', 'a': 'dictionary'}
When I run it, it fails with
Expected:
{'this': 'is', 'a': 'dictionary'}
Got:
{'a': 'dictionary', 'this': 'is'}
My best guess as to the cause of this failure is that doctest isn't checking dictionary equality, but __repr__
equality. This post indicates that there's some way to trick doctest into checking dictionary equality. How can I do this?