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

前端 未结 7 1475
眼角桃花
眼角桃花 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:57

    I ended up using this. Hacky, but it works.

    >>> p = my_function()
    >>> {'this': 'is', 'a': 'dictionary'} == p
    True
    

提交回复
热议问题