]:
with self.subTest(name_base):
name = self.name + '_' + name_base
- with self.assertRaises(SystemError):
+ with self.assertRaises(SystemError) as cm:
self.load_module_by_name(name)
+ # If there is an unreported exception, it should be chained
+ # with the `SystemError`.
+ if "unreported_exception" in name_base:
+ self.assertIsNotNone(cm.exception.__cause__)
+
def test_nonascii(self):
# Test that modules with non-ASCII names can be loaded.
# punycode behaves slightly differently in some-ASCII and no-ASCII
--- /dev/null
+Raising SystemError on import will now have its cause be set to the original unexpected exception.
goto error;
} else {
if (PyErr_Occurred()) {
- PyErr_Format(PyExc_SystemError,
- "creation of module %s raised unreported exception",
- name);
+ _PyErr_FormatFromCause(
+ PyExc_SystemError,
+ "creation of module %s raised unreported exception",
+ name);
goto error;
}
}
return -1;
}
if (PyErr_Occurred()) {
- PyErr_Format(
+ _PyErr_FormatFromCause(
PyExc_SystemError,
"execution of module %s raised unreported exception",
name);
}
goto error;
} else if (PyErr_Occurred()) {
- PyErr_Clear();
- PyErr_Format(
+ _PyErr_FormatFromCause(
PyExc_SystemError,
"initialization of %s raised unreported exception",
name_buf);