From b62dc60c9817d726cf17a2ed32ef708911f1b9f5 Mon Sep 17 00:00:00 2001 From: Tomasz Kontusz Date: Wed, 3 Jun 2015 17:05:03 +0200 Subject: [PATCH] [1.8.x] Fixed ImportError message in utils.module_loading.import_string() Backport of c2b4967e76fd671e6199e4dd54d2a2c1f096b8eb from master --- django/utils/module_loading.py | 2 +- tests/utils_tests/test_module_loading.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py index b94119a3b4..eaa5f669d1 100644 --- a/django/utils/module_loading.py +++ b/django/utils/module_loading.py @@ -29,7 +29,7 @@ def import_string(dotted_path): return getattr(module, class_name) except AttributeError: msg = 'Module "%s" does not define a "%s" attribute/class' % ( - dotted_path, class_name) + module_path, class_name) six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) diff --git a/tests/utils_tests/test_module_loading.py b/tests/utils_tests/test_module_loading.py index f11bfa44cd..0aeec13a8a 100644 --- a/tests/utils_tests/test_module_loading.py +++ b/tests/utils_tests/test_module_loading.py @@ -150,8 +150,10 @@ class ModuleImportTestCase(unittest.TestCase): # Test exceptions raised self.assertRaises(ImportError, import_string, 'no_dots_in_path') - self.assertRaises(ImportError, import_string, 'utils_tests.unexistent') self.assertRaises(ImportError, import_string, 'unexistent.path') + msg = 'Module "utils_tests" does not define a "unexistent" attribute' + with six.assertRaisesRegex(self, ImportError, msg): + import_string('utils_tests.unexistent') @modify_settings(INSTALLED_APPS={'append': 'utils_tests.test_module'})