Issue #14592: A relative import will raise a KeyError if __package__

or __name__ are not set in globals.

Thanks to Stefan Behnel for the bug report.
This commit is contained in:
Brett Cannon 2012-04-17 19:05:11 -04:00
parent 09b86d1196
commit 273323cf68
3 changed files with 10 additions and 1 deletions

View file

@ -203,6 +203,11 @@ class RelativeImports(unittest.TestCase):
self.assertEqual(mod.__name__, 'crash.mod')
self.relative_import_test(create, globals_, callback)
def test_relative_import_no_globals(self):
# No globals for a relative import is an error.
with self.assertRaises(KeyError):
import_util.import_('sys', level=1)
def test_main():
from test.support import run_unittest