From 0bc79fc543d9d359c60927a4245da4bdc645c404 Mon Sep 17 00:00:00 2001 From: Ben Cail Date: Fri, 3 Feb 2023 09:41:01 -0500 Subject: [PATCH] PR review --- django/core/management/__init__.py | 1 - tests/settings_tests/tests.py | 14 ++++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index ea4add3744..b56cfcfb3d 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -385,7 +385,6 @@ class ManagementUtility: # The following commands can be run without a valid settings file configured if subcommand not in {"startproject", "startapp", "makemessages"}: sys.stderr.write(str(exc) + "\n") - self.settings_exception = exc if settings.configured: # Start the auto-reloading dev server even if the code is broken. diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py index d2abbbfb6f..6f45b21aa3 100644 --- a/tests/settings_tests/tests.py +++ b/tests/settings_tests/tests.py @@ -339,19 +339,13 @@ class SettingsTests(SimpleTestCase): settings._setup() def test_unable_to_import_settings_module(self): - with self.assertRaisesMessage( - ImproperlyConfigured, - "Settings module fake_settings_module could not be imported", - ): + msg = "Settings module fake_settings_module could not be imported" + with self.assertRaisesMessage(ImproperlyConfigured, msg): 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" - ) - - with mock.patch("importlib.import_module", mock_import_module): + exc = ModuleNotFoundError("No module named 'fake_module'", name="fake_module") + with mock.patch("importlib.import_module", side_effect=exc): with self.assertRaisesMessage(ImportError, "No module named 'fake_module'"): Settings("fake_settings_module")