Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(170130)

Side by Side Diff: Doc/library/test.rst

Issue 17987: test.support.captured_stderr, captured_stdin not documented
Patch Set: Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/support.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`test` --- Regression tests package for Python 1 :mod:`test` --- Regression tests package for Python
2 =================================================== 2 ===================================================
3 3
4 .. module:: test 4 .. module:: test
5 :synopsis: Regression tests package containing the testing suite for Python. 5 :synopsis: Regression tests package containing the testing suite for Python.
6 .. sectionauthor:: Brett Cannon <brett@python.org> 6 .. sectionauthor:: Brett Cannon <brett@python.org>
7 7
8 .. note:: 8 .. note::
9 The :mod:`test` package is meant for internal use by Python only. It is 9 The :mod:`test` package is meant for internal use by Python only. It is
10 documented for the benefit of the core developers of Python. Any use of 10 documented for the benefit of the core developers of Python. Any use of
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 assert len(w.warnings) == 0 355 assert len(w.warnings) == 0
356 356
357 357
358 Here all warnings will be caught, and the test code tests the captured 358 Here all warnings will be caught, and the test code tests the captured
359 warnings directly. 359 warnings directly.
360 360
361 .. versionchanged:: 3.2 361 .. versionchanged:: 3.2
362 New optional arguments *filters* and *quiet*. 362 New optional arguments *filters* and *quiet*.
363 363
364 364
365 .. function:: captured_stdout() 365 .. function:: captured_stderr()
storchaka 2013/05/28 15:37:20 I think functions should be mentioned in order of
366 captured_stdout()
366 367
367 A context manager that runs the :keyword:`with` statement body using a 368 A context managers that temporarily replaces the
368 :class:`io.StringIO` object as sys.stdout. That object can be retrieved 369 :data:`sys.stderr` / :data:`sys.stdout` stream with :class:`io.StringIO` obje ct.
369 using the ``as`` clause of the :keyword:`with` statement.
370 370
371 Example use:: 371 Example use::
372 372
373 with captured_stdout() as s: 373 with captured_stderr() as s:
storchaka 2013/05/28 15:37:20 captured_stdout() is much more used and stdout usu
374 print("hello") 374 print("hello", file=sys.stderr)
375 assert s.getvalue() == "hello\n" 375 assert s.getvalue() == "hello\n"
376
377
378 .. function:: captured_stdin()
379
380 A context manager that temporarily replaces the :data:`sys.stdin` stream with
381 :class:`io.StringIO` object.
382
383 Example use::
384
385 with captured_stdin() as s:
386 s.write('hello\n')
387 s.seek(0)
388 # call test code that consumes from stdin
389 captured = input()
390 self.assertEqual(captured, "hello")
376 391
377 392
378 .. function:: temp_cwd(name='tempcwd', quiet=False, path=None) 393 .. function:: temp_cwd(name='tempcwd', quiet=False, path=None)
379 394
380 A context manager that temporarily changes the current working 395 A context manager that temporarily changes the current working
381 directory (CWD). 396 directory (CWD).
382 397
383 An existing path may be provided as *path*, in which case this function 398 An existing path may be provided as *path*, in which case this function
384 makes no changes to the file system. 399 makes no changes to the file system.
385 400
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 568
554 .. method:: EnvironmentVarGuard.unset(envvar) 569 .. method:: EnvironmentVarGuard.unset(envvar)
555 570
556 Temporarily unset the environment variable ``envvar``. 571 Temporarily unset the environment variable ``envvar``.
557 572
558 573
559 .. class:: WarningsRecorder() 574 .. class:: WarningsRecorder()
560 575
561 Class used to record warnings for unit tests. See documentation of 576 Class used to record warnings for unit tests. See documentation of
562 :func:`check_warnings` above for more details. 577 :func:`check_warnings` above for more details.
OLDNEW
« no previous file with comments | « no previous file | Lib/test/support.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+