else:
self.fail("No exception raised")
+ def test_class_cause_nonexception_result(self):
+ class ConstructsNone(BaseException):
+ @classmethod
+ def __new__(*args, **kwargs):
+ return None
+ try:
+ raise IndexError from ConstructsNone
+ except TypeError as e:
+ self.assertIn("should have returned an instance of BaseException", str(e))
+ except IndexError:
+ self.fail("Wrong kind of exception raised")
+ else:
+ self.fail("No exception raised")
+
def test_instance_cause(self):
cause = KeyError()
try:
fixed_cause = _PyObject_CallNoArgs(cause);
if (fixed_cause == NULL)
goto raise_error;
+ if (!PyExceptionInstance_Check(fixed_cause)) {
+ _PyErr_Format(tstate, PyExc_TypeError,
+ "calling %R should have returned an instance of "
+ "BaseException, not %R",
+ cause, Py_TYPE(fixed_cause));
+ goto raise_error;
+ }
Py_DECREF(cause);
}
else if (PyExceptionInstance_Check(cause)) {