python doctest失败错误

标签 python doctest

我正在尝试对此代码运行 doctest,这是我收到的错误。任何人都可以解释语法中到底缺少什么,因为预期的结果和得到的结果是相同的。

文档测试:

"""
>>> d.display()
Inorder traversal keys
2 3 4 5 9 10
Preorder traversal keys
4 3 2 9 5 10
Postorder traversal keys
2 3 5 10 9 4
"""

失败结果:

Failed example:
d.display()
Expected:
Inorder traversal keys
2 3 4 5 9 10
Preorder traversal keys
4 3 2 9 5 10
Postorder traversal keys
2 3 5 10 9 4
Got:
Inorder traversal keys
2 3 4 5 9 10 
Preorder traversal keys
4 3 2 9 5 10 
Postorder traversal keys
2 3 5 10 9 4
**********************************************************************
1 items had failures:
   1 of   9 in __main__.BinarySearchTreeDict
***Test Failed*** 1 failures.

进程已完成,退出代码为 0

最佳答案

您的 display() 函数中似乎有一个额外的空格用于中序遍历键 和预序遍历键。 (通过手动突出显示失败结果的 ExpectedGot 部分中的每一行来发现这一点)

2 3 4 5 9 10 # has an extra whitespace

4 3 2 9 5 10 # has an extra whitespace

关于python doctest失败错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32921366/

相关文章:

python - 在python中获取 float 的小数部分

python - 无法连接到 MSK 上的 Kafka

python - 在 python 程序中使用 doctest 和登录

python - web2py:创建传递参数的文档测试

python - Python doctest 中限制浮点精度比较的最佳方法

python - 如何使用 MySQLdb 在 Python 中创建跨多个语句的事务?

python - 如何使用 tf.contrib.estimator.forward_features

python - 查找两个或多个以 upper 开头的连续单词并替换为它们的缩写(正则表达式)

ipython - 可以在jupyter单元函数上运行python doctest吗?

python - 嵌套文档字符串的 Doctest