diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-07-11 16:28:40 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-07-11 16:28:40 (GMT) |
commit | 5a33f813483325ab3e13596814c3eade6e0bb518 (patch) | |
tree | 81f815e9ff3830ff8b81757054f47e5956398138 /Doc | |
parent | dfde2151ede820873324705403af3176093b5ef5 (diff) | |
download | cpython-5a33f813483325ab3e13596814c3eade6e0bb518.zip cpython-5a33f813483325ab3e13596814c3eade6e0bb518.tar.gz cpython-5a33f813483325ab3e13596814c3eade6e0bb518.tar.bz2 |
#17987: properly document support.captured_xxx.
Patch by Dmi Baranov.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/test.rst | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 702ef8a..bf78b4d 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -362,17 +362,29 @@ The :mod:`test.support` module defines the following functions: New optional arguments *filters* and *quiet*. -.. function:: captured_stdout() +.. function:: captured_stdin() + captured_stdout() + captured_stderr() - A context manager that runs the :keyword:`with` statement body using a - :class:`io.StringIO` object as sys.stdout. That object can be retrieved - using the ``as`` clause of the :keyword:`with` statement. + A context managers that temporarily replaces the named stream with + :class:`io.StringIO` object. - Example use:: + Example use with output streams:: - with captured_stdout() as s: + with captured_stdout() as stdout, captured_stderr() as stderr: print("hello") - assert s.getvalue() == "hello\n" + print("error", file=sys.stderr) + assert stdout.getvalue() == "hello\n" + assert stderr.getvalue() == "error\n" + + Example use with input stream:: + + with captured_stdin() as stdin: + stdin.write('hello\n') + stdin.seek(0) + # call test code that consumes from sys.stdin + captured = input() + self.assertEqual(captured, "hello") .. function:: temp_cwd(name='tempcwd', quiet=False, path=None) |