diff options
author | Georg Brandl <georg@python.org> | 2007-08-24 18:27:43 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-08-24 18:27:43 (GMT) |
commit | d558f67d5dfb13168b172012489925aaab47cfd0 (patch) | |
tree | 374627610ee87a924bb1a3a602fb4bbd59895ab5 | |
parent | 692bbc4790546a42405ace5c61f0c239ebd6e351 (diff) | |
download | cpython-d558f67d5dfb13168b172012489925aaab47cfd0.zip cpython-d558f67d5dfb13168b172012489925aaab47cfd0.tar.gz cpython-d558f67d5dfb13168b172012489925aaab47cfd0.tar.bz2 |
Document new utility functions in test_support.
-rw-r--r-- | Doc/library/test.rst | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 8972091..90b4db3 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -284,8 +284,38 @@ The :mod:`test.test_support` module defines the following functions: This will run all tests defined in the named module. -The :mod:`test.test_support` module defines the following classes: +.. function:: catch_warning() + + This is a context manager that guards the warnings filter from being + permanently changed and records the data of the last warning that has been + issued. + + Use like this:: + + with catch_warning() as w: + warnings.warn("foo") + assert str(w.message) == "foo" + + .. versionadded:: 2.6 + + +.. function:: captured_stdout() + + This is a context manager than runs the :keyword:`with` statement body using + a :class:`StringIO.StringIO` object as sys.stdout. That object can be + retrieved using the ``as`` clause of the with statement. + + Example use:: + + with captured_stdout() as s: + print "hello" + assert s.getvalue() == "hello" + + .. versionadded:: 2.6 + + +The :mod:`test.test_support` module defines the following classes: .. class:: TransientResource(exc[, **kwargs]) @@ -314,4 +344,3 @@ The :mod:`test.test_support` module defines the following classes: .. method:: EnvironmentVarGuard.unset(envvar) Temporarily unset the environment variable ``envvar``. - |