diff --git a/graphs_trees/utils/captured_output.py b/graphs_trees/utils/captured_output.py new file mode 100644 index 0000000..99aaf0e --- /dev/null +++ b/graphs_trees/utils/captured_output.py @@ -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 \ No newline at end of file