diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index d6395e0a03..2500d0b70e 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -317,6 +317,8 @@ class ManagementUtility: settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc + except ImportError as exc: + self.settings_exception = exc if settings.configured: # Start the auto-reloading dev server even if the code is broken. diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index e56d43c4bc..1670af86fb 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -236,6 +236,16 @@ class DjangoAdminNoSettings(AdminScriptTestCase): self.assertNoOutput(out) self.assertOutput(err, "No module named '?bad_settings'?", regex=True) + def test_commands_with_invalid_settings(self): + """" + Commands that don't require settings succeed if the settings file + doesn't exist. + """ + args = ['startproject'] + out, err = self.run_django_admin(args, settings_file='bad_settings') + self.assertNoOutput(out) + self.assertOutput(err, "You must provide a project name", regex=True) + class DjangoAdminDefaultSettings(AdminScriptTestCase): """A series of tests for django-admin.py when using a settings.py file that