diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-14 05:43:25 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-05-14 05:43:25 (GMT) |
commit | e728d72d8afba6f5dde330f99e7a336f183122eb (patch) | |
tree | 48af3e3c77049df0e50b154c24ba90761a5acf82 /Lib | |
parent | 6b60fb9148738de1525bbf5c7ddadc16a474c635 (diff) | |
parent | fc778fd06753178a817b4aa51ddb8dd503fe7ea8 (diff) | |
download | cpython-e728d72d8afba6f5dde330f99e7a336f183122eb.zip cpython-e728d72d8afba6f5dde330f99e7a336f183122eb.tar.gz cpython-e728d72d8afba6f5dde330f99e7a336f183122eb.tar.bz2 |
#7960: merge with 3.1.
Diffstat (limited to 'Lib')
-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 bd35fde..b1ca9dd 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -891,14 +891,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()) @@ -908,6 +902,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(): |