catch nasty exception classes with __new__ that doesn't return a exception (closes #11627)

Patch from Andreas Stührk.
This commit is contained in:
Benjamin Peterson 2011-07-15 14:09:26 -05:00
parent 1f0ccfa853
commit 5afa03a72e
3 changed files with 19 additions and 0 deletions

View file

@ -121,6 +121,15 @@ class TestRaise(unittest.TestCase):
else:
self.fail("No exception raised")
def test_new_returns_invalid_instance(self):
# See issue #11627.
class MyException(Exception):
def __new__(cls, *args):
return object()
with self.assertRaises(TypeError):
raise MyException
class TestCause(unittest.TestCase):
def test_invalid_cause(self):