MCPcopy Index your code
hub / github.com/python/cpython / captured_output

Function captured_output

Lib/test/support/__init__.py:895–904  ·  view source on GitHub ↗

Return a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO.

(stream_name)

Source from the content-addressed store, hash-verified

893
894@contextlib.contextmanager
895def captured_output(stream_name):
896 """Return a context manager used by captured_stdout/stdin/stderr
897 that temporarily replaces the sys stream *stream_name* with a StringIO."""
898 import io
899 orig_stdout = getattr(sys, stream_name)
900 setattr(sys, stream_name, io.StringIO())
901 try:
902 yield getattr(sys, stream_name)
903 finally:
904 setattr(sys, stream_name, orig_stdout)
905
906def captured_stdout():
907 """Capture the output of sys.stdout:

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…