[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:53:26 EDT 2019


https://github.com/python/cpython/commit/52c99aeb9f454b26baca61c545202057c7259bcf
commit: 52c99aeb9f454b26baca61c545202057c7259bcf
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-09-13T03:53:22-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 0bd4772dbb6e..9baac3cf3b95 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -161,9 +161,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