MCPcopy Index your code
hub / github.com/RustPython/RustPython / captured_output

Function captured_output

Lib/test/support/__init__.py:807–816  ·  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

805
806@contextlib.contextmanager
807def captured_output(stream_name):
808 """Return a context manager used by captured_stdout/stdin/stderr
809 that temporarily replaces the sys stream *stream_name* with a StringIO."""
810 import io
811 orig_stdout = getattr(sys, stream_name)
812 setattr(sys, stream_name, io.StringIO())
813 try:
814 yield getattr(sys, stream_name)
815 finally:
816 setattr(sys, stream_name, orig_stdout)
817
818def captured_stdout():
819 """Capture the output of sys.stdout:

Calls 2

getattrFunction · 0.85
setattrFunction · 0.85