fd = os.open(TESTMOD, os.O_CREAT, 000)
try:
os.close(fd)
- self.assertZipFailure(TESTMOD)
+
+ with self.assertRaises(zipimport.ZipImportError) as cm:
+ zipimport.zipimporter(TESTMOD)
+ self.assertIsInstance(cm.exception.__context__, PermissionError)
finally:
# If we leave "the read-only bit" set on Windows, nothing can
# delete TESTMOD, and later tests suffer bogus failures.
fp = _Py_fopen_obj(archive, "rb");
if (fp == NULL) {
- if (PyErr_ExceptionMatches(PyExc_OSError))
+ if (PyErr_ExceptionMatches(PyExc_OSError)) {
+ PyObject *exc, *val, *tb;
+ PyErr_Fetch(&exc, &val, &tb);
PyErr_Format(ZipImportError, "can't open Zip file: %R", archive);
+ _PyErr_ChainExceptions(exc, val, tb);
+ }
return NULL;
}