Added unit testing utility to redirect print output to help validate some functions.

This commit is contained in:
Donne Martin 2015-08-01 09:24:19 -04:00
parent 33cb8826ad
commit 757eca26f1

View File

@ -0,0 +1,14 @@
import sys
from contextlib import contextmanager
from StringIO import StringIO
@contextmanager
def captured_output():
new_out, new_err = StringIO(), StringIO()
old_out, old_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = new_out, new_err
yield sys.stdout, sys.stderr
finally:
sys.stdout, sys.stderr = old_out, old_err