Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, unittest: Can one make the TestRunner completely quiet?

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.

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

like image 363
Eskil Avatar asked Jul 01 '10 11:07

Eskil


1 Answers

TextTestRunner has a stream=sys.stderr in its constructor:

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

Change it to a null stream.

result = unittest.TextTestRunner(stream = open(os.devnull, 'w')).run(alltests)
if len(result.failures) or len(result.errors):
    print "Sorry."
like image 60
Tal Weiss Avatar answered Oct 19 '22 21:10

Tal Weiss