Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法让unittest.TextTestRunner完全安静,这意味着它永远不会自行打印输出?即使在verbosity=0它完成后也会打印结果。
verbosity=0
我想在打印任何内容之前处理跑步者返回的 TestResult 对象。
TextTestRunnerstream=sys.stderr在其构造函数中有一个:
stream=sys.stderr
def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1)
将其更改为空流。
result = unittest.TextTestRunner(stream = open(os.devnull, 'w')).run(alltests) if len(result.failures) or len(result.errors): print "Sorry."