assertRaises as context manager now allows you to access exception as documented
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index ab04382..04a7322 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -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:
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 63408e3..4acfa65 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -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: