summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMatthias Bussonnier <bussonniermatthias@gmail.com>2017-02-22 15:06:50 (GMT)
committerBarry Warsaw <barry@python.org>2017-02-22 15:06:50 (GMT)
commit1bc156430bad8177b5beecf57979628c1d071230 (patch)
tree1f24f4fa81da3e01e94b15e138d13e7dcdb2bbcb /Lib/test
parentd37c068e695f8ec72b5c1b5a5a5ece2337fda768 (diff)
downloadcpython-1bc156430bad8177b5beecf57979628c1d071230.zip
cpython-1bc156430bad8177b5beecf57979628c1d071230.tar.gz
cpython-1bc156430bad8177b5beecf57979628c1d071230.tar.bz2
bpo-29546: Improve from-import error message with location (#103)
bpo-29546: Improve from-import error message with location
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_import/__init__.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index df678f1..ace1a46 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -85,6 +85,15 @@ class ImportTests(unittest.TestCase):
from os import i_dont_exist
self.assertEqual(cm.exception.name, 'os')
self.assertEqual(cm.exception.path, os.__file__)
+ self.assertRegex(str(cm.exception), "cannot import name 'i_dont_exist' from 'os' \(.*/Lib/os.py\)")
+
+ def test_from_import_missing_attr_has_name_and_so_path(self):
+ import _opcode
+ with self.assertRaises(ImportError) as cm:
+ from _opcode import i_dont_exist
+ self.assertEqual(cm.exception.name, '_opcode')
+ self.assertEqual(cm.exception.path, _opcode.__file__)
+ self.assertRegex(str(cm.exception), "cannot import name 'i_dont_exist' from '_opcode' \(.*\.(so|dll)\)")
def test_from_import_missing_attr_has_name(self):
with self.assertRaises(ImportError) as cm:
@@ -365,9 +374,12 @@ class ImportTests(unittest.TestCase):
module_name = 'test_from_import_AttributeError'
self.addCleanup(unload, module_name)
sys.modules[module_name] = AlwaysAttributeError()
- with self.assertRaises(ImportError):
+ with self.assertRaises(ImportError) as cm:
from test_from_import_AttributeError import does_not_exist
+ self.assertEqual(str(cm.exception),
+ "cannot import name 'does_not_exist' from '<unknown module name>' (unknown location)")
+
@skip_if_dont_write_bytecode
class FilePermissionTests(unittest.TestCase):