File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -712,14 +712,8 @@ def filter_error(err):
712712
713713@contextlib .contextmanager
714714def 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
731725def 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
734734def gc_collect ():
You can’t perform that action at this time.
0 commit comments