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: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d8f2d0bdb3d3b9abe53cda9add979e2fc4be7da0;p=thirdparty%2FPython%2Fcpython.git 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 6f739af3fb2c..04a0ab857400 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")