diff options
author | Georg Brandl <georg@python.org> | 2010-02-07 17:02:22 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-02-07 17:02:22 (GMT) |
commit | dc3694bee021480980d5b66a93f69ce137ee5be4 (patch) | |
tree | 5b4700577b3764372ae965ba32c23de2b65f7fe8 | |
parent | 4ad752d70f211dc24ef96474d266005d08c35923 (diff) | |
download | cpython-dc3694bee021480980d5b66a93f69ce137ee5be4.zip cpython-dc3694bee021480980d5b66a93f69ce137ee5be4.tar.gz cpython-dc3694bee021480980d5b66a93f69ce137ee5be4.tar.bz2 |
Rename "exc_value" attribute on assertRaises context manager to "exception".
-rw-r--r-- | Doc/library/unittest.rst | 4 | ||||
-rw-r--r-- | Lib/test/test_unittest.py | 10 | ||||
-rw-r--r-- | Lib/unittest/case.py | 4 |
3 files changed, 5 insertions, 13 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index 0115ffa..b1d27d2 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -898,13 +898,13 @@ Test cases do_something() The context manager will store the caught exception object in its - :attr:`exc_value` attribute. This can be useful if the intention + :attr:`exception` attribute. This can be useful if the intention is to perform additional checks on the exception raised:: with self.assertRaises(SomeException) as cm: do_something() - the_exception = cm.exc_value + the_exception = cm.exception self.assertEqual(the_exception.error_code, 3) .. versionchanged:: 2.7 diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index 8314262..ab04382 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -6,8 +6,6 @@ Still need testing: TestCase.{assert,fail}* methods (some are tested implicitly) """ -from StringIO import StringIO -import __builtin__ import os import re import sys @@ -626,7 +624,6 @@ class Test_TestLoader(TestCase): # a good chance that it won't be imported when this test is run module_name = 'audioop' - import sys if module_name in sys.modules: del sys.modules[module_name] @@ -1014,7 +1011,6 @@ class Test_TestLoader(TestCase): # a good chance that it won't be imported when this test is run module_name = 'audioop' - import sys if module_name in sys.modules: del sys.modules[module_name] @@ -1962,8 +1958,6 @@ class Test_TestResult(TestCase): # methods. Contains formatted tracebacks instead # of sys.exc_info() results." def test_addFailure(self): - import sys - class Foo(unittest.TestCase): def test_1(self): pass @@ -2012,8 +2006,6 @@ class Test_TestResult(TestCase): # methods. Contains formatted tracebacks instead # of sys.exc_info() results." def test_addError(self): - import sys - class Foo(unittest.TestCase): def test_1(self): pass @@ -2888,7 +2880,7 @@ test case ctx = self.assertRaises(ExceptionMock) with ctx: Stub(v) - e = ctx.exc_value + e = ctx.exception self.assertIsInstance(e, ExceptionMock) self.assertEqual(e.args[0], v) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 854ebc4..63408e3 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -104,7 +104,7 @@ class _AssertRaisesContext(object): if not issubclass(exc_type, self.expected): # let unexpected exceptions pass through return False - self.exc_value = exc_value #store for later retrieval + self.exception = exc_value # store for later retrieval if self.expected_regexp is None: return True @@ -389,7 +389,7 @@ class TestCase(object): with self.assertRaises(SomeException) as cm: do_something() - the_exception = cm.exc_value + the_exception = cm.exception self.assertEqual(the_exception.error_code, 3) """ context = _AssertRaisesContext(excClass, self) |