diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-02-05 21:13:40 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-02-05 21:13:40 (GMT) |
commit | 41531f2e19eeb0803650e6a44576f0b5eafb2c2b (patch) | |
tree | 244635f47dcdb9e352a915c6dc3cff66249f8d0a | |
parent | e9abbeecf2c8db6f6b2ee86040b1742ada6648ac (diff) | |
download | cpython-41531f2e19eeb0803650e6a44576f0b5eafb2c2b.zip cpython-41531f2e19eeb0803650e6a44576f0b5eafb2c2b.tar.gz cpython-41531f2e19eeb0803650e6a44576f0b5eafb2c2b.tar.bz2 |
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.
........
-rw-r--r-- | Doc/library/unittest.rst | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index 4adc106..3f7680b 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -892,14 +892,20 @@ Test cases 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 |