Issue #14599: Generalize a test for ImportError.path and add support

in Python/dynload_shlibs.c.

This should fix the remaining importlib test failure on Windows.
Support in AIX and HP-UX will be in a separate checkin.
This commit is contained in:
Brett Cannon 2012-04-20 15:22:50 -04:00
parent 3c23a87e58
commit f0434e647a
4 changed files with 26 additions and 27 deletions

View file

@ -337,28 +337,6 @@ class ImportTests(unittest.TestCase):
del sys.path[0]
remove_files(TESTFN)
@unittest.skipUnless(sys.platform == "win32", "Windows-specific")
def test_extension_import_fail(self):
# Issue 1559549 added `name` and `path` attributes to ImportError
# in order to provide better detail. Issue 10854 implemented those
# attributes on import failures of extensions on Windows.
debug = True if sys.executable[-6:] == "_d.exe" else False
pkg_name = "extension"
pkg_file = pkg_name + "{}".format("_d.pyd" if debug else ".pyd")
with open(pkg_file, "w"): pass
importlib.invalidate_caches()
try:
with self.assertRaises(ImportError) as err:
import extension
self.assertEqual(err.exception.name, pkg_name)
# The path we get back has the dot-slash, e.g., ".\\extension.pyd"
self.assertIsNotNone(err.exception.path,
'unexpected None for ImportError.path: '
'{!r}'.format(err.exception))
self.assertEqual(os.path.relpath(err.exception.path), pkg_file)
finally:
unlink(pkg_file)
class PycRewritingTests(unittest.TestCase):
# Test that the `co_filename` attribute on code objects always points