diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-14 05:44:12 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-14 05:44:12 (GMT) |
commit | 6b8934053a7fac93706b2b80f57bd4102754516f (patch) | |
tree | cc14d61842a8d7e95bd9823a7dc3137177c618ec /Lib/test/support.py | |
parent | 32e3fdc2d06404c3d5ae637f862a3ce194ea9252 (diff) | |
parent | e728d72d8afba6f5dde330f99e7a336f183122eb (diff) | |
download | cpython-6b8934053a7fac93706b2b80f57bd4102754516f.zip cpython-6b8934053a7fac93706b2b80f57bd4102754516f.tar.gz cpython-6b8934053a7fac93706b2b80f57bd4102754516f.tar.bz2 |
#7960: merge with 3.2.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r-- | Lib/test/support.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 579f2b7..d6f0e0d 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -887,14 +887,8 @@ def transient_internet(resource_name, *, timeout=30.0, errnos=()): @contextlib.contextmanager def captured_output(stream_name): - """Run the 'with' statement body using a StringIO object in place of a - specific attribute on the sys module. - Example use (with 'stream_name=stdout'):: - - with captured_stdout() as s: - print("hello") - assert s.getvalue() == "hello" - """ + """Return a context manager used by captured_stdout and captured_stdin + that temporarily replaces the sys stream *stream_name* with a StringIO.""" import io orig_stdout = getattr(sys, stream_name) setattr(sys, stream_name, io.StringIO()) @@ -904,6 +898,12 @@ def captured_output(stream_name): setattr(sys, stream_name, orig_stdout) def captured_stdout(): + """Capture the output of sys.stdout: + + with captured_stdout() as s: + print("hello") + self.assertEqual(s.getvalue(), "hello") + """ return captured_output("stdout") def captured_stderr(): |