I\'m writing a doctest for a function that outputs a dictionary. The doctest looks like
>>> my_function()
{\'this\': \'is\', \'a\': \'dictionary\'}
You can create an instance of unittest.TestCase class inside your doctests, and use it to compare dictionaries:
def my_function(x):
"""
>>> from unittest import TestCase
>>> t = TestCase()
>>> t.assertDictEqual(
... my_function('a'),
... {'this': 'is', 'a': 'dictionary'}
... )
>>> t.assertDictEqual(
... my_function('b'),
... {'this': 'is', 'b': 'dictionary'}
... )
"""
return {'this': 'is', x: 'dictionary'}
Note: this approach is better than simply checking if dictionaries are equal, because it will show diff between the two dictionaries.