Fix the ImportWarning regarding __spec__ and __package__ being None (GH-16003)

This commit is contained in:
Xtreak 2019-09-12 10:29:36 +01:00 committed by Brett Cannon
parent 8ed6503eca
commit 6e1a30b15e
1 changed files with 4 additions and 3 deletions

View File

@ -161,6 +161,7 @@ class BuiltinTest(unittest.TestCase):
self.assertRaises(ValueError, __import__, '')
self.assertRaises(TypeError, __import__, 'sys', name='sys')
# Relative import outside of a package with no __package__ or __spec__ (bpo-37409).
with self.assertWarns(ImportWarning):
self.assertRaises(ImportError, __import__, '',
{'__package__': None, '__spec__': None, '__name__': '__main__'},
locals={}, fromlist=('foo',), level=1)