diff --git a/django/conf/__init__.py b/django/conf/__init__.py index b0a448ca1e..986ea44c72 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -168,7 +168,9 @@ class Settings: except ImportError as exc: # If the settings module cannot be imported, treat it as a configuration error. if exc.name == self.SETTINGS_MODULE: - raise ImproperlyConfigured(f"Settings module {self.SETTINGS_MODULE} could not be imported") from exc + raise ImproperlyConfigured( + f"Settings module {self.SETTINGS_MODULE} could not be imported" + ) from exc raise tuple_settings = ( diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 5e104e098d..aa20424208 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -383,8 +383,8 @@ class ManagementUtility: except ImproperlyConfigured as exc: self.settings_exception = exc # The following commands can be run even without a valid settings file configured - if subcommand not in {'startproject', 'startapp', 'makemessages'}: - sys.stderr.write(str(exc) + '\n') + if subcommand not in {"startproject", "startapp", "makemessages"}: + sys.stderr.write(str(exc) + "\n") self.settings_exception = exc if settings.configured: diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py index f1b59359b3..d2abbbfb6f 100644 --- a/tests/settings_tests/tests.py +++ b/tests/settings_tests/tests.py @@ -340,17 +340,20 @@ class SettingsTests(SimpleTestCase): def test_unable_to_import_settings_module(self): with self.assertRaisesMessage( - ImproperlyConfigured, "Settings module fake_settings_module could not be imported" + ImproperlyConfigured, + "Settings module fake_settings_module could not be imported", ): - Settings('fake_settings_module') + Settings("fake_settings_module") def test_unable_to_import_a_random_module(self): def mock_import_module(_): - raise ModuleNotFoundError("No module named 'fake_module'", name="fake_module") + raise ModuleNotFoundError( + "No module named 'fake_module'", name="fake_module" + ) with mock.patch("importlib.import_module", mock_import_module): with self.assertRaisesMessage(ImportError, "No module named 'fake_module'"): - Settings('fake_settings_module') + Settings("fake_settings_module") class TestComplexSettingOverride(SimpleTestCase):