make test_support's captured_output a bit more robust when exceptions happen

This commit is contained in:
Benjamin Peterson 2008-04-30 21:03:58 +00:00
parent 63b0a2eb21
commit d8f2d0bdb3
1 changed files with 4 additions and 2 deletions

View File

@ -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")