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

Skip to content

Commit e728d72

Browse files
committed
#7960: merge with 3.1.
2 parents 6b60fb9 + fc778fd commit e728d72

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
@@ -891,14 +891,8 @@ def filter_error(err):
891891

892892
@contextlib.contextmanager
893893
def captured_output(stream_name):
894-
"""Run the 'with' statement body using a StringIO object in place of a
895-
specific attribute on the sys module.
896-
Example use (with 'stream_name=stdout')::
897-
898-
with captured_stdout() as s:
899-
print("hello")
900-
assert s.getvalue() == "hello"
901-
"""
894+
"""Return a context manager used by captured_stdout and captured_stdin
895+
that temporarily replaces the sys stream *stream_name* with a StringIO."""
902896
import io
903897
orig_stdout = getattr(sys, stream_name)
904898
setattr(sys, stream_name, io.StringIO())
@@ -908,6 +902,12 @@ def captured_output(stream_name):
908902
setattr(sys, stream_name, orig_stdout)
909903

910904
def captured_stdout():
905+
"""Capture the output of sys.stdout:
906+
907+
with captured_stdout() as s:
908+
print("hello")
909+
self.assertEqual(s.getvalue(), "hello")
910+
"""
911911
return captured_output("stdout")
912912

913913
def captured_stderr():

0 commit comments

Comments
 (0)