mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #32915 - Don't catch ImportErrors unless it's the settings module that can't be imported
Based on work by Rohith PR and others in PR #14622
This commit is contained in:
@@ -1412,12 +1412,12 @@ class ManageSettingsWithSettingsErrors(AdminScriptTestCase):
|
||||
self.write_settings(
|
||||
"settings.py",
|
||||
extra="from django.core.exceptions import ImproperlyConfigured\n"
|
||||
"raise ImproperlyConfigured()",
|
||||
"raise ImproperlyConfigured('Improper configuration')",
|
||||
)
|
||||
args = ["help"]
|
||||
out, err = self.run_manage(args)
|
||||
self.assertOutput(out, "only Django core commands are listed")
|
||||
self.assertNoOutput(err)
|
||||
self.assertOutput(err, "Improper configuration")
|
||||
|
||||
|
||||
class ManageCheck(AdminScriptTestCase):
|
||||
|
||||
@@ -338,6 +338,20 @@ class SettingsTests(SimpleTestCase):
|
||||
with self.assertRaisesMessage(ValueError, "Incorrect timezone setting: test"):
|
||||
settings._setup()
|
||||
|
||||
def test_unable_to_import_settings_module(self):
|
||||
with self.assertRaisesMessage(
|
||||
ImproperlyConfigured, "Settings module fake_settings_module could not be imported"
|
||||
):
|
||||
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):
|
||||
with self.assertRaisesMessage(ImportError, "No module named 'fake_module'"):
|
||||
Settings('fake_settings_module')
|
||||
|
||||
|
||||
class TestComplexSettingOverride(SimpleTestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user