From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 13 Sep 2019 10:53:22 +0000 (-0700) Subject: Fix the ImportWarning regarding __spec__ and __package__ being None (GH-16003) X-Git-Tag: v3.8.0rc1~123 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=52c99aeb9f454b26baca61c545202057c7259bcf;p=python Fix the ImportWarning regarding __spec__ and __package__ being None (GH-16003) (cherry picked from commit 6e1a30b15e73ebc82e6790495fd54cc8971723ec) Co-authored-by: Xtreak --- diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 0bd4772dbb..9baac3cf3b 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -161,9 +161,10 @@ 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). - self.assertRaises(ImportError, __import__, '', - {'__package__': None, '__spec__': None, '__name__': '__main__'}, - locals={}, fromlist=('foo',), level=1) + with self.assertWarns(ImportWarning): + self.assertRaises(ImportError, __import__, '', + {'__package__': None, '__spec__': None, '__name__': '__main__'}, + locals={}, fromlist=('foo',), level=1) # embedded null character self.assertRaises(ModuleNotFoundError, __import__, 'string\x00')