diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index b6a7d53a0c..fdbf5c26eb 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -262,10 +262,10 @@ class ManagementUtility(object): # Output an extra note if settings are not properly configured try: settings.INSTALLED_APPS - except ImproperlyConfigured as e: + except ImproperlyConfigured as err: usage.append(style.NOTICE( "Note that only Django core commands are listed as settings " - "are not properly configured (error: %s)." % e)) + "are not properly configured (error: %s)." % err)) return '\n'.join(usage) @@ -280,6 +280,8 @@ class ManagementUtility(object): try: app_name = commands[subcommand] except KeyError: + # This might trigger ImproperlyConfigured (masked in get_commands) + settings.INSTALLED_APPS sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % (subcommand, self.prog_name)) sys.exit(1) diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 4c3ee36b66..4f41e876bc 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -275,7 +275,7 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase): args = ['noargs_command'] out, err = self.run_django_admin(args) self.assertNoOutput(out) - self.assertOutput(err, "Unknown command: 'noargs_command'") + self.assertOutput(err, "settings are not configured") def test_custom_command_with_settings(self): "default: django-admin can execute user commands if settings are provided as argument" @@ -342,7 +342,7 @@ class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase): args = ['noargs_command'] out, err = self.run_django_admin(args) self.assertNoOutput(out) - self.assertOutput(err, "Unknown command: 'noargs_command'") + self.assertOutput(err, "settings are not configured") def test_custom_command_with_settings(self): "fulldefault: django-admin can execute user commands if settings are provided as argument" @@ -409,7 +409,7 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase): args = ['noargs_command'] out, err = self.run_django_admin(args) self.assertNoOutput(out) - self.assertOutput(err, "Unknown command: 'noargs_command'") + self.assertOutput(err, "settings are not configured") def test_custom_command_with_settings(self): "minimal: django-admin can't execute user commands, even if settings are provided as argument" @@ -476,7 +476,7 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase): args = ['noargs_command'] out, err = self.run_django_admin(args) self.assertNoOutput(out) - self.assertOutput(err, "Unknown command: 'noargs_command'") + self.assertOutput(err, "settings are not configured") def test_custom_command_with_settings(self): "alternate: django-admin can execute user commands if settings are provided as argument" @@ -546,7 +546,7 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase): args = ['noargs_command'] out, err = self.run_django_admin(args) self.assertNoOutput(out) - self.assertOutput(err, "Unknown command: 'noargs_command'") + self.assertOutput(err, "settings are not configured") def test_custom_command_with_settings(self): "alternate: django-admin can execute user commands if settings are provided as argument" @@ -620,7 +620,7 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase): args = ['noargs_command'] out, err = self.run_django_admin(args) self.assertNoOutput(out) - self.assertOutput(err, "Unknown command: 'noargs_command'") + self.assertOutput(err, "settings are not configured") def test_builtin_with_settings(self): "directory: django-admin builtin commands succeed if settings are provided as argument"