summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2016-01-23 00:39:02 (GMT)
committerBrett Cannon <brett@python.org>2016-01-23 00:39:02 (GMT)
commit9fa812668faf0d2d7839845e1a0da19b87bdbc29 (patch)
tree80c2c811909e691d6ab1fc2fea7ad9ca1619bdd7 /Lib/test/test_importlib
parent4b18dd339a9919e6f5fa3485c8b871ed19d9e391 (diff)
downloadcpython-9fa812668faf0d2d7839845e1a0da19b87bdbc29.zip
cpython-9fa812668faf0d2d7839845e1a0da19b87bdbc29.tar.gz
cpython-9fa812668faf0d2d7839845e1a0da19b87bdbc29.tar.bz2
Issue #18018: Raise an ImportError if a relative import is attempted
with no known parent package. Previously SystemError was raised if the parent package didn't exist (e.g., __package__ was set to ''). Thanks to Florent Xicluna and Yongzhi Pan for reporting the issue.
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r--Lib/test/test_importlib/import_/test_relative_imports.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/import_/test_relative_imports.py b/Lib/test/test_importlib/import_/test_relative_imports.py
index 0409f22..1cad6b3 100644
--- a/Lib/test/test_importlib/import_/test_relative_imports.py
+++ b/Lib/test/test_importlib/import_/test_relative_imports.py
@@ -213,6 +213,11 @@ class RelativeImports:
with self.assertRaises(KeyError):
self.__import__('sys', level=1)
+ def test_relative_import_no_package(self):
+ with self.assertRaises(ImportError):
+ self.__import__('a', {'__package__': '', '__spec__': None},
+ level=1)
+
(Frozen_RelativeImports,
Source_RelativeImports