diff options
author | Brett Cannon <brett@python.org> | 2013-07-12 15:22:26 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-07-12 15:22:26 (GMT) |
commit | a79e4fb38d6e598be56944ead5753e65ad561bab (patch) | |
tree | f3a0f201b80165802e325096d8535c5b9eb0083b /Lib | |
parent | f0cb69274c735ae5d178acf4bfe7e314b046eb57 (diff) | |
download | cpython-a79e4fb38d6e598be56944ead5753e65ad561bab.zip cpython-a79e4fb38d6e598be56944ead5753e65ad561bab.tar.gz cpython-a79e4fb38d6e598be56944ead5753e65ad561bab.tar.bz2 |
Issue #18342: Use the repr of a module name for ``from ... import
...`` when an ImportError occurs.
Other cases had already been switched over to using the repr.
Thanks to Tomasz Maćkowiak for the patch.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_import.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index e6a4379..61df86a 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -321,6 +321,14 @@ class ImportTests(unittest.TestCase): stdout, stderr = popen.communicate() self.assertIn(b"ImportError", stdout) + def test_from_import_message_for_nonexistent_module(self): + with self.assertRaisesRegexp(ImportError, "^No module named 'bogus'"): + from bogus import foo + + def test_from_import_message_for_existing_module(self): + with self.assertRaisesRegexp(ImportError, "^cannot import name 'bogus'"): + from re import bogus + @skip_if_dont_write_bytecode class FilePermissionTests(unittest.TestCase): |