@contextlib.contextmanager<EOL>def capture_stdout():
stdout = sys.stdout<EOL>sys.stdout = six.moves.cStringIO()<EOL>try:<EOL><INDENT>yield sys.stdout<EOL><DEDENT>finally:<EOL><INDENT>sys.stdout = stdout<EOL><DEDENT>
Intercept standard output in a with-context
    :return: cStringIO instance

    >>> with capture_stdout() as stdout:
            ...
        print stdout.getvalue()