相关疑难解决方法(0)

如何使用Python的doctest-package测试字典相等性?

我正在为输出字典的函数编写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来检查字典的相同性.我怎样才能做到这一点?

python doctest dictionary

37
推荐指数
3
解决办法
5418
查看次数

标签 统计

dictionary ×1

doctest ×1

python ×1