@contextmanager
def override_stdouts():
 (prev_out, prev_err) = (sys.stdout, sys.stderr)
 (mystdout, mystderr) = (WhateverIO(), WhateverIO())
 sys.stdout = sys.__stdout__ = mystdout
 sys.stderr = sys.__stderr__ = mystderr
 (yield (mystdout, mystderr))
 sys.stdout = sys.__stdout__ = prev_out
 sys.stderr = sys.__stderr__ = prev_err

@ contextmanager def override_stdouts ( ) : ( prev_out , prev_err ) = ( sys . stdout , sys . stderr ) ( mystdout , mystderr ) = ( WhateverIO ( ) , WhateverIO ( ) ) sys . stdout = sys . __stdout__ = mystdout sys . stderr = sys . __stderr__ = mystderr ( yield ( mystdout , mystderr ) ) sys . stdout = sys . __stdout__ = prev_out sys . stderr = sys . __stderr__ = prev_err
override sys .