Kaydet (Commit) 2bd52dcc authored tarafından Michael Foord's avatar Michael Foord

assertRaises as context manager now allows you to access exception as documented

üst a4f46e12
......@@ -3059,8 +3059,13 @@ class Test_Assertions(TestCase):
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:
......
......@@ -91,7 +91,7 @@ class _AssertRaisesContext(object):
self.expected_regexp = expected_regexp
def __enter__(self):
pass
return self
def __exit__(self, exc_type, exc_value, tb):
if exc_type is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment