@contextmanager<EOL>def redirect_output(stream, target):
original = getattr(sys, stream)<EOL>try:<EOL><INDENT>setattr(sys, stream, target)<EOL>yield<EOL><DEDENT>finally:<EOL><INDENT>setattr(sys, stream, original)<EOL><DEDENT>
Temporary redirector for stdout and stderr