import doctest
def create_grid(size):
grid = []
for i in range(size):
row = ['0']*size
grid.append(row)
"""
>>> create_grid(4)
[['0', '0', '0', '0'], ['0', '0', '0', '0'],
['0', '0', '0', '0'], ['0', '0', '0', '0']]
"""
return grid
if __name__ == '__main__':
doctest.testmod()
运行上面python Test_av_doctest.py -v
提供了以下消息:文档测试不运行测试,
2 items had no tests:
__main__
__main__.create_grid
0 tests in 2 items.
0 passed and 0 failed.
Test passed.
为什么会出现此错误的任何想法?
你能提供更多的细节吗?你的整个python文件是什么样的?你在使用'doctest.testmod'吗?或者你使用'doctest.testfile'并将它指向上面的文本文件? – Colin