我正处于使用 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/