_stderr = sys.stderr
_stdout = sys.stdout
null = open(os.devnull, 'wb')
sys.stdout = sys.stderr = null
print('Bleh')
sys.stderr = _stderr
sys.stdout = _stdout
print('Bleh')
How to temporary hide stdout or stderr while running a unittest in Python