我正在为输出字典的函数编写doctest.doctest看起来像
>>> my_function()
{'this': 'is', 'a': 'dictionary'}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它失败了
Expected:
{'this': 'is', 'a': 'dictionary'}
Got:
{'a': 'dictionary', 'this': 'is'}
Run Code Online (Sandbox Code Playgroud)
我对这个失败原因的最好猜测是doctest不是检查字典的平等,而是检查__repr__平等.这篇文章表明有一些方法可以欺骗doctest来检查字典的相同性.我怎样才能做到这一点?