Comparing dictionaries in doctest

Here’s a nifty way to compare dictionaries in doctest in Python.

 

>>> d = function_that_returns_a_dict()

>>> expected_d = {… some expected result }

>>> d = True if d == expected_d else d
>>> d
True

Technorati tags: ,
Custom Search