Python, unittest: Is it possible to make TestRunner completely calm?

Is there a way to make unittest.TextTestRunner completely silent, which means it never prints on its own? Even with verbosity=0 it prints the results upon completion.

I want to process the TestResult object returned by the runner before anything is printed.

+6
python unit-testing verbosity
source share
1 answer

TextTestRunner has stream=sys.stderr in its constructor:

 def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1) 

Change it to an empty thread.

 result = unittest.TextTestRunner(stream = open(os.devnull, 'w')).run(alltests) if len(result.failures) or len(result.errors): print "Sorry." 
+7
source share

All Articles