我很困惑为什么doctest.testmod()
以奇怪的顺序调用测试函数
from doctest import testmod
def test_forwrite():
'''
>>> test_forwrite()
OP: Done
'''
write()
def test_forread():
'''
>>> test_forread()
OP: Done
'''
read()
if __name__ == "__main__":
testmod(verbose = True)
为什么不考虑其定义的test_forread()
总是首先测试的顺序
测试按名称排序
test_forread
按字母顺序在test_forwrite()
之前排序从^{} source code 到^{} method :
doctest.testmod()
uses ^{然而,您的测试不应依赖于给定的排序。编写独立的测试,这样就可以单独或并行运行测试
这是因为testmod函数通过按字母顺序调用给定模块/程序中的函数来测试它们
在您的情况下,
test_forread()
将首先被调用,因为当按字母顺序排序时,它位于test_forwrite()
之前相关问题 更多 >
编程相关推荐