python doctest : expected result is the same as the "got" result but the test failed

标签 python doctest

我正处于使用 python 作为软件 QA 工具的学习阶段。

我编写了下一个简单测试,以便在文本文件编号矩阵中找到字母“a”。 问题是测试失败,即使期望值等于我得到的结果。

这是为什么呢?你能告诉我我做错了什么吗?

测试脚本:

fin = open("abc.txt", "r")

arr_fin = []

for line in fin:
    arr_fin.append(line.split())

print arr_fin

for row in arr_fin:     
   arr_fin_1 = " ".join('{0:4}'.format(i or " ") for i in row) 
   print arr_fin_1



def find_letter(x, arr_fin_1):
    """
    >>> find_letter('a', arr_fin_1)
    97 
    """
    t=ord(x) #exchange to letter's ASCII value
    for i in arr_fin_1:
        if i==x:
            print t
            return;

def _test():
    import doctest
    doctest.testmod()

if __name__ == "__main__":
    _test()

错误信息:

Expected:
    97 
Got:
    97
**********************************************************************
1 items had failures:
   1 of   1 in __main__.find_letter
***Test Failed*** 1 failures.

最佳答案

您在 97 之后有一个额外的空间 - 如果您删除它,您的测试应该可以正常运行。

关于 python doctest : expected result is the same as the "got" result but the test failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5856502/

相关文章:

python - 如何从 pybuilder 运行文档测试?

Python doctest 不能在名为 signal.py 的文件上运行

Python 和 libxml2 : how to iterate in xml nodes with XPATH

python - Python 中的 float 概念

python - Django:无效的 block 标记 'form.username'

python - python模块的单元测试基础设施

python - Celery 不适用于带有 "--autoreload"选项的 RabbitMQ

实现ftps的Python模块

python 文档测试和协程

python - Doctest 在 Sphinx 中不起作用,无法导入 python 文件 Python