]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix the ImportWarning regarding __spec__ and __package__ being None (GH-16003)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 13 Sep 2019 10:54:34 +0000 (03:54 -0700)
committerGitHub <noreply@github.com>
Fri, 13 Sep 2019 10:54:34 +0000 (03:54 -0700)
(cherry picked from commit 6e1a30b15e73ebc82e6790495fd54cc8971723ec)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
Lib/test/test_builtin.py

index 5216da459f671546545a0c636b12133f4cf7c3c0..c60560ea6d3a0a5fef73a8004a70daa82ea6d682 100644 (file)
@@ -155,9 +155,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')