From: Benjamin Peterson Date: Wed, 30 Apr 2008 21:03:58 +0000 (+0000) Subject: make test_support's captured_output a bit more robust when exceptions happen X-Git-Tag: v2.6a3~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8f2d0bdb3d3b9abe53cda9add979e2fc4be7da0;p=python make test_support's captured_output a bit more robust when exceptions happen --- diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 6f739af3fb..04a0ab8574 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -482,8 +482,10 @@ def captured_output(stream_name): import StringIO orig_stdout = getattr(sys, stream_name) setattr(sys, stream_name, StringIO.StringIO()) - yield getattr(sys, stream_name) - setattr(sys, stream_name, orig_stdout) + try: + yield getattr(sys, stream_name) + finally: + setattr(sys, stream_name, orig_stdout) def captured_stdout(): return captured_output("stdout")