[Python-checkins] r78094 - in python/trunk/Lib: test/test_unittest.py unittest/case.py
michael.foord
python-checkins at python.org
Sun Feb 7 19:44:13 CET 2010
Author: michael.foord
Date: Sun Feb 7 19:44:12 2010
New Revision: 78094
Log:
assertRaises as context manager now allows you to access exception as documented
Modified:
python/trunk/Lib/test/test_unittest.py
python/trunk/Lib/unittest/case.py
Modified: python/trunk/Lib/test/test_unittest.py
==============================================================================
--- python/trunk/Lib/test/test_unittest.py (original)
+++ python/trunk/Lib/test/test_unittest.py Sun Feb 7 19:44:12 2010
@@ -3059,8 +3059,13 @@
pass
else:
self.fail("assertRaises() didn't let exception pass through")
- with self.assertRaises(KeyError):
- raise KeyError
+ with self.assertRaises(KeyError) as cm:
+ try:
+ raise KeyError
+ except Exception, e:
+ raise
+ self.assertIs(cm.exception, e)
+
with self.assertRaises(KeyError):
raise KeyError("key")
try:
Modified: python/trunk/Lib/unittest/case.py
==============================================================================
--- python/trunk/Lib/unittest/case.py (original)
+++ python/trunk/Lib/unittest/case.py Sun Feb 7 19:44:12 2010
@@ -91,7 +91,7 @@
self.expected_regexp = expected_regexp
def __enter__(self):
- pass
+ return self
def __exit__(self, exc_type, exc_value, tb):
if exc_type is None:
More information about the Python-checkins
mailing list