diff --git a/tests/saltunittest.py b/tests/saltunittest.py index 15426f0e4f..1f022a40cc 100644 --- a/tests/saltunittest.py +++ b/tests/saltunittest.py @@ -74,6 +74,7 @@ class RedirectStdStreams(object): def __enter__(self): self.redirect() + return self def __exit__(self, exc_type, exc_value, traceback): self.unredirect() @@ -90,14 +91,33 @@ class RedirectStdStreams(object): def unredirect(self): if not self.__redirected: return + try: + self.__stdout.flush() + self.__stdout.close() + except ValueError: + # already closed? + pass + try: + self.__stderr.flush() + self.__stderr.close() + except ValueError: + # already closed? + pass - self.__stdout.flush() - self.__stdout.close() - self.__stderr.flush() - self.__stderr.close() sys.stdout = self.old_stdout sys.stderr = self.old_stderr + def flush(self): + if self.__redirected: + try: + self.__stdout.flush() + except: + pass + try: + self.__stderr.flush() + except: + pass + class TestsLoggingHandler(object): '''