Python doctest因“equal”而失败;“预期”;及;得到;
我尝试在我的场景中使用doctest:Python doctest因“equal”而失败;“预期”;及;得到;,python,doctest,Python,Doctest,我尝试在我的场景中使用doctest: def cycle(*its): """Return the cyclic iterator. >>> c = cycle([1,2,3]) >>> [next(c) for i in range(10)] [1, 2, 3, 1, 2, 3, 1, 2, 3, 1] """ saved = [] for it in its: for el i
def cycle(*its):
"""Return the cyclic iterator.
>>> c = cycle([1,2,3])
>>> [next(c) for i in range(10)]
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
"""
saved = []
for it in its:
for el in it:
saved.append(el)
yield el
while True:
for el in saved:
yield el
if __name__ == "__main__":
import doctest
doctest.testmod()
但我却失败了:
Trying:
c = cycle([1,2,3])
Expecting nothing
ok
Trying:
[next(c) for i in range(10)]
Expecting:
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
**********************************************************************
File "D:\work\python_questions\iterators.py", line 7, in __main__.cycle
Failed example:
[next(c) for i in range(10)]
Expected:
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
Got:
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
1 items had no tests:
__main__
**********************************************************************
1 items had failures:
1 of 2 in __main__.cycle
2 tests in 2 items.
1 passed and 1 failed.
***Test Failed*** 1 failures.
为什么期望:[1,2,3,1,2,3,1,2,3,1]和得到:[1,2,3,1,2,3,1,2,3,1]不相等?(Windows7上的Python 3.6.1)检查预期值之后的隐藏空格或选项卡。例如
[1,2,3,1,2,3,1,2,3,1]\
您可以很容易地看到他们选择了整个预期行(甚至在上面的帖子中)。
希望它有助于在预期值之后检查隐藏的空格或制表符。例如
[1,2,3,1,2,3,1,2,3,1]\
您可以很容易地看到他们选择了整个预期行(甚至在上面的帖子中)。
希望它能帮上忙,但如果我们改成>>[下一步(c)范围内的i(10)]=[1,2,3,2,3,1],真的,更难用:现在你的例子可以用了,但不是一刻前它就很难用了,但是如果我们改成>[下一步(c)范围内的i(10)]=[1,2,3,1,2,3,1]
,True
–它可以工作。它更尴尬:现在您的示例可以工作了,但不是片刻之前