[Python-checkins] r78000 - in python/branches/py3k: Doc/library/unittest.rst
michael.foord
python-checkins at python.org
Fri Feb 5 22:13:40 CET 2010
Author: michael.foord
Date: Fri Feb 5 22:13:40 2010
New Revision: 78000
Log:
Merged revisions 77999 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77999 | michael.foord | 2010-02-05 21:07:38 +0000 (Fri, 05 Feb 2010) | 1 line
Example of using assertRaises as a context manager in the unittest documentation.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/library/unittest.rst
Modified: python/branches/py3k/Doc/library/unittest.rst
==============================================================================
--- python/branches/py3k/Doc/library/unittest.rst (original)
+++ python/branches/py3k/Doc/library/unittest.rst Fri Feb 5 22:13:40 2010
@@ -892,14 +892,20 @@
If only the *exception* argument is given, returns a context manager so
that the code under test can be written inline rather than as a function::
- with self.failUnlessRaises(some_error_class):
+ with self.assertRaises(SomeException):
do_something()
The context manager will store the caught exception object in its
:attr:`exc_value` attribute. This can be useful if the intention
- is to perform additional checks on the exception raised.
+ is to perform additional checks on the exception raised::
- .. versionchanged:: 3.1
+ with self.assertRaises(SomeException) as cm:
+ do_something()
+
+ the_exception = cm.exc_value
+ self.assertEquals(the_exception.error_code, 3)
+
+ .. versionchanged:: 3.1
Added the ability to use :meth:`assertRaises` as a context manager.
.. deprecated:: 3.1
More information about the Python-checkins
mailing list