Skip to content

Instantly share code, notes, and snippets.

@ironpythonbot
Created December 9, 2014 17:52
Show Gist options
  • Save ironpythonbot/970318018ad0563baa23 to your computer and use it in GitHub Desktop.
Save ironpythonbot/970318018ad0563baa23 to your computer and use it in GitHub Desktop.
CodePlex Issue #30119 Plain Text Attachments
import unittest
from System import InvalidOperationException
class Issue(unittest.TestCase):
def test_assertRaises(self):
with self.assertRaises(InvalidOperationException):
raise InvalidOperationException('assertRaises should catch this')
Only in unittest: __main__.py
diff -u --recursive -b a/lib/unittest/case.py b/lib/unittest/case.py
--- a/lib/unittest/case.py 2010-08-24 13:53:44.000000000 -1000
+++ b/lib/unittest/case.py 2011-02-07 12:19:52.545875000 -1000
@@ -1,5 +1,6 @@
"""Test case implementation"""
+import clr
import sys
import functools
import difflib
@@ -110,10 +111,15 @@
exc_name = str(self.expected)
raise self.failureException(
"{0} not raised".format(exc_name))
- if not issubclass(exc_type, self.expected):
- # let unexpected exceptions pass through
+ # Save an expected exception in self.exception.
+ # Let any other exception propagate through.
+ if issubclass(exc_type, self.expected):
+ self.exception = exc_value
+ elif (hasattr(exc_value, 'clsException') and
+ isinstance(exc_value.clsException, self.expected)):
+ self.exception = exc_value.clsException
+ else:
return False
- self.exception = exc_value # store for later retrieval
if self.expected_regexp is None:
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment