#NEWLINE# @ contextmanager #NEWLINE# def capture_output( ) : #NEWLINE# #INDENT# ( new_out , new_err ) = ( StringIO ( ) , StringIO ( ) ) #NEWLINE# ( old_out , old_err ) = ( sys . stdout , sys . stderr ) #NEWLINE# try : #NEWLINE# #INDENT# ( sys . stdout , sys . stderr ) = ( new_out , new_err ) #NEWLINE# ( yield ( sys . stdout , sys . stderr ) ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# ( sys . stdout , sys . stderr ) = ( old_out , old_err )