#NEWLINE# @ contextmanager #NEWLINE# def capture_stderr( ) : #NEWLINE# #INDENT# old_stderr = sys . stderr #NEWLINE# new_stderr = StringIO ( ) #NEWLINE# sys . stderr = old_stderr #NEWLINE# ( yield new_stderr ) #NEWLINE# sys . stderr = old_stderr #NEWLINE# new_stderr . close ( )