Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc778fd

Browse files
committed
#7960: fix docstrings for captured_output and captured_stdout.
1 parent 3c0d8a1 commit fc778fd

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Lib/test/support.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,8 @@ def filter_error(err):
712712

713713
@contextlib.contextmanager
714714
def captured_output(stream_name):
715-
"""Run the 'with' statement body using a StringIO object in place of a
716-
specific attribute on the sys module.
717-
Example use (with 'stream_name=stdout')::
718-
719-
with captured_stdout() as s:
720-
print("hello")
721-
assert s.getvalue() == "hello"
722-
"""
715+
"""Return a context manager used by captured_stdout and captured_stdin
716+
that temporarily replaces the sys stream *stream_name* with a StringIO."""
723717
import io
724718
orig_stdout = getattr(sys, stream_name)
725719
setattr(sys, stream_name, io.StringIO())
@@ -729,6 +723,12 @@ def captured_output(stream_name):
729723
setattr(sys, stream_name, orig_stdout)
730724

731725
def captured_stdout():
726+
"""Capture the output of sys.stdout:
727+
728+
with captured_stdout() as s:
729+
print("hello")
730+
self.assertEqual(s.getvalue(), "hello")
731+
"""
732732
return captured_output("stdout")
733733

734734
def gc_collect():

0 commit comments

Comments
 (0)