Python,unittest:可以让 TestRunner 完全安静吗? [英] Python, unittest: Can one make the TestRunner completely quiet?
本文介绍了Python,unittest:可以让 TestRunner 完全安静吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让 unittest.TextTestRunner完全安静,这意味着它永远不会自行打印输出?即使在 verbosity=0
完成后,它也会打印结果.
Is there a way to make unittest.TextTestRunner completely quiet, meaning it never prints to output on its own? Even at verbosity=0
it prints results when done.
我想在打印任何内容之前处理运行程序返回的 TestResult 对象.
I want to process the TestResult object returned by the runner before anything is printed.
推荐答案
TextTestRunner 在其构造函数中有一个 stream=sys.stderr
:
TextTestRunner has a stream=sys.stderr
in its constructor:
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."
这篇关于Python,unittest:可以让 TestRunner 完全安静吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文