summaryrefslogtreecommitdiff
path: root/tests/migrations
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-11-20 13:52:24 -0500
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-15 15:24:57 -0500
commit0071cb1efd559d721e5882da2e18556f867eed76 (patch)
treec5ddf927892bd49e4617bd2a13576926a99465a6 /tests/migrations
parent2ce5cb0f7a4618dfdc5f5c10e53e2e9b9543d298 (diff)
Refs #36652 -- Avoided missing imports in a temporary file generated in a migration test.
Diffstat (limited to 'tests/migrations')
-rw-r--r--tests/migrations/test_loader.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
index efa7a94166..705d49d069 100644
--- a/tests/migrations/test_loader.py
+++ b/tests/migrations/test_loader.py
@@ -682,8 +682,11 @@ class LoaderTests(TestCase):
with tempfile.NamedTemporaryFile(
mode="w", encoding="utf-8", suffix=".py", dir=tests_dir, delete=False
) as test_settings:
+ self.addCleanup(os.remove, test_settings.name)
for attr, value in settings._wrapped.__dict__.items():
- if attr.isupper():
+ # Only write builtin values so that any settings that reference
+ # a value that needs an import are omitted.
+ if attr.isupper() and type(value).__module__ == "builtins":
test_settings.write(f"{attr} = {value!r}\n")
# Provide overrides here, instead of via decorators.
test_settings.write(f"DATABASES = {settings.DATABASES}\n")
@@ -693,8 +696,6 @@ class LoaderTests(TestCase):
"INSTALLED_APPS=[a for a in INSTALLED_APPS if a.startswith('django')]\n"
)
test_settings.write(f"INSTALLED_APPS += {INSTALLED_APPS}\n")
- test_settings_name = test_settings.name
- self.addCleanup(os.remove, test_settings_name)
test_environ = os.environ.copy()
test_environ["PYTHONPATH"] = str(tests_dir)
@@ -709,7 +710,7 @@ class LoaderTests(TestCase):
"app1",
"--skip-checks",
"--settings",
- Path(test_settings_name).stem,
+ Path(test_settings.name).stem,
]
try:
subprocess.run(