diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-02-08 21:57:48 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-02-08 21:57:48 (GMT) |
commit | 490082302779decbaf66a80480ae45fba6ae0e20 (patch) | |
tree | d559eff683af5b3beee37137a96f9cf3ada3c747 /Lib/unittest/case.py | |
parent | 7b26d7f82f67649a7c72f7bd30bf9248f6f542bc (diff) | |
download | cpython-490082302779decbaf66a80480ae45fba6ae0e20.zip cpython-490082302779decbaf66a80480ae45fba6ae0e20.tar.gz cpython-490082302779decbaf66a80480ae45fba6ae0e20.tar.bz2 |
Merged revisions 78091,78094,78109 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78091 | georg.brandl | 2010-02-07 19:02:22 +0200 (Sun, 07 Feb 2010) | 1 line
Rename "exc_value" attribute on assertRaises context manager to "exception".
........
r78094 | michael.foord | 2010-02-07 20:44:12 +0200 (Sun, 07 Feb 2010) | 1 line
assertRaises as context manager now allows you to access exception as documented
........
r78109 | ezio.melotti | 2010-02-08 23:52:08 +0200 (Mon, 08 Feb 2010) | 1 line
Fix exc_value -> exception in docstring
........
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r-- | Lib/unittest/case.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 8632652..a4e45aa 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -99,7 +99,7 @@ class _AssertRaisesContext(object): self.expected_regex = expected_regexp def __enter__(self): - pass + return self def __exit__(self, exc_type, exc_value, tb): if exc_type is None: @@ -116,8 +116,8 @@ class _AssertRaisesContext(object): if not issubclass(exc_type, self.expected): # let unexpected exceptions pass through return False - #store exception, without traceback, for later retrieval - self.exc_value = exc_value.with_traceback(None) + # store exception, without traceback, for later retrieval + self.exception = exc_value.with_traceback(None) if self.expected_regex is None: return True @@ -397,12 +397,12 @@ class TestCase(object): do_something() The context manager keeps a reference to the exception as - the exc_value attribute. This allows you to inspect the + the 'exception' attribute. This allows you to inspect the exception after the assertion:: 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, callableObj) |