File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -891,14 +891,8 @@ def filter_error(err):
891891
892892@contextlib .contextmanager
893893def 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
910904def 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
913913def captured_stderr ():
You can’t perform that action at this time.
0 commit comments