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.
This commit is contained in:
Brett Cannon 2013-07-12 11:22:26 -04:00
parent f0cb69274c
commit a79e4fb38d
4 changed files with 13 additions and 1 deletions

View file

@ -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):