diff options
| author | inondle <qfulsher@gmail.com> | 2016-06-01 13:08:59 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-02 10:37:00 -0400 |
| commit | 080dd74e016fbc99d3aaecd36ef932424042b768 (patch) | |
| tree | 6ed5c00bf301b024ffd717c43b0c9f8595b05b8a | |
| parent | 779829662d48a54ac427574e5e0c279b69519e42 (diff) | |
Fixed #26616 -- Improved error message when AppConfig.name is invalid.
| -rw-r--r-- | django/apps/config.py | 9 | ||||
| -rw-r--r-- | tests/apps/tests.py | 3 |
2 files changed, 10 insertions, 2 deletions
diff --git a/django/apps/config.py b/django/apps/config.py index edd7a48a6f..88e52c1f05 100644 --- a/django/apps/config.py +++ b/django/apps/config.py @@ -139,7 +139,14 @@ class AppConfig(object): "'%s' must supply a name attribute." % entry) # Ensure app_name points to a valid module. - app_module = import_module(app_name) + try: + app_module = import_module(app_name) + except ImportError: + raise ImproperlyConfigured( + "Cannot import '%s'. Check that '%s.%s.name' is correct." % ( + app_name, mod_path, cls_name, + ) + ) # Entry is a path to an app config class. return cls(app_name, app_module) diff --git a/tests/apps/tests.py b/tests/apps/tests.py index c7fff0e738..639ce97758 100644 --- a/tests/apps/tests.py +++ b/tests/apps/tests.py @@ -78,7 +78,8 @@ class AppsTests(SimpleTestCase): with self.assertRaises(ImportError): with self.settings(INSTALLED_APPS=['there is no such app']): pass - with self.assertRaises(ImportError): + msg = "Cannot import 'there is no such app'. Check that 'apps.apps.NoSuchApp.name' is correct." + with self.assertRaisesMessage(ImproperlyConfigured, msg): with self.settings(INSTALLED_APPS=['apps.apps.NoSuchApp']): pass |
