[Python-checkins] Fix the ImportWarning regarding __spec__ and __package__ being None (GH-16003)

Miss Islington (bot) webhook-mailer at python.org
Fri Sep 13 06:54:37 EDT 2019


https://github.com/python/cpython/commit/d3f8a11c06b7daa8df6ebf90ac711460e72b7a77
commit: d3f8a11c06b7daa8df6ebf90ac711460e72b7a77
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-09-13T03:54:34-07:00
summary:

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

(cherry picked from commit 6e1a30b15e73ebc82e6790495fd54cc8971723ec)

Co-authored-by: Xtreak <tir.karthi at gmail.com>

files:
M Lib/test/test_builtin.py

diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 5216da459f67..c60560ea6d3a 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -155,9 +155,10 @@ def test_import(self):
         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')
 



More information about the Python-checkins mailing list