From d8f2d0bdb3d3b9abe53cda9add979e2fc4be7da0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 30 Apr 2008 21:03:58 +0000 Subject: [PATCH] make test_support's captured_output a bit more robust when exceptions happen --- Lib/test/test_support.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 6f739af3fb2..04a0ab85740 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")