mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-24792: Fix zipimporter masking the cause of import errors (GH-22204)
zipimport's _unmarshal_code swallows import errors and then _get_module_code doesn't know the cause of the error, and returns the generic, and sometimes incorrect, 'could not find...'. Automerge-Triggered-By: GH:brettcannon
This commit is contained in:
parent
e8d2264210
commit
fb34096140
5 changed files with 748 additions and 737 deletions
|
@ -242,10 +242,10 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
files = {TESTMOD + pyc_ext: (NOW, badmagic_pyc)}
|
||||
try:
|
||||
self.doTest(".py", files, TESTMOD)
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
self.fail("expected ImportError; import from bad pyc")
|
||||
self.fail("This should not be reached")
|
||||
except zipimport.ZipImportError as exc:
|
||||
self.assertIsInstance(exc.__cause__, ImportError)
|
||||
self.assertIn("magic number", exc.__cause__.msg)
|
||||
|
||||
def testBadMTime(self):
|
||||
badtime_pyc = bytearray(test_pyc)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue