mirror of https://github.com/django/django.git
Fixed #26616 -- Improved error message when AppConfig.name is invalid.
This commit is contained in:
parent
779829662d
commit
080dd74e01
|
@ -139,7 +139,14 @@ class AppConfig(object):
|
||||||
"'%s' must supply a name attribute." % entry)
|
"'%s' must supply a name attribute." % entry)
|
||||||
|
|
||||||
# Ensure app_name points to a valid module.
|
# Ensure app_name points to a valid module.
|
||||||
|
try:
|
||||||
app_module = import_module(app_name)
|
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.
|
# Entry is a path to an app config class.
|
||||||
return cls(app_name, app_module)
|
return cls(app_name, app_module)
|
||||||
|
|
|
@ -78,7 +78,8 @@ class AppsTests(SimpleTestCase):
|
||||||
with self.assertRaises(ImportError):
|
with self.assertRaises(ImportError):
|
||||||
with self.settings(INSTALLED_APPS=['there is no such app']):
|
with self.settings(INSTALLED_APPS=['there is no such app']):
|
||||||
pass
|
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']):
|
with self.settings(INSTALLED_APPS=['apps.apps.NoSuchApp']):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue