Index: Doc/library/unittest.rst =================================================================== --- Doc/library/unittest.rst (revision 83976) +++ Doc/library/unittest.rst (working copy) @@ -1036,7 +1036,8 @@ :meth:`assertRaises`. The test passes if *exception* is raised, is an error if another exception is raised, or fails if no exception is raised. To catch any of a group of exceptions, a tuple containing the exception - classes may be passed as *exception*. + classes may be passed as *exception*. If the test passes then the raised + exception is returned. 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:: @@ -1058,7 +1059,7 @@ Added the ability to use :meth:`assertRaises` as a context manager. .. versionchanged:: 3.2 - Added the :attr:`exception` attribute. + Added the :attr:`exception` attribute and raised exception return value. .. deprecated:: 3.1 :meth:`failUnlessRaises`; use :meth:`assertRaises`. Index: Lib/unittest/test/test_assertions.py =================================================================== --- Lib/unittest/test/test_assertions.py (revision 83976) +++ Lib/unittest/test/test_assertions.py (working copy) @@ -92,6 +92,10 @@ else: self.fail("assertRaises() didn't let exception pass through") + e = IndexError() + ex = self.assertRaises(type(e), _raise, e) + self.assertIs(ex, e) + def testAssertNotRegexpMatches(self): self.assertNotRegexpMatches('Ala ma kota', r'r+') try: Index: Lib/unittest/case.py =================================================================== --- Lib/unittest/case.py (revision 83976) +++ Lib/unittest/case.py (working copy) @@ -441,7 +441,9 @@ arguments kwargs. If a different type of exception is thrown, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an - unexpected exception. + unexpected exception. If an expected exception is raised + then the exception object is returned for inspection by the + caller. If called with callableObj omitted or None, will return a context object used like this:: @@ -463,6 +465,7 @@ return context with context: callableObj(*args, **kwargs) + return context.exception def _getAssertEqualityFunc(self, first, second): """Get a detailed comparison function for the types of the two args.