How do I test dictionary-equality with Python's doctest-package?

前端 未结 7 1473
眼角桃花
眼角桃花 2020-12-09 07:15

I\'m writing a doctest for a function that outputs a dictionary. The doctest looks like

>>> my_function()
{\'this\': \'is\', \'a\': \'dictionary\'}
         


        
7条回答
  •  攒了一身酷
    2020-12-09 07:52

    turn it into a list via dict.items() and then sort it ...

    >>> l = my_function().items()
    >>> l.sort()
    >>> l
    [('a', 'dictionary'), ('this', 'is')]
    

提交回复
热议问题