1
0
mirror of https://github.com/django/django.git synced 2025-04-01 03:56:42 +00:00

Fixed #35402 -- Fixed crash when DatabaseFeatures.django_test_skips references a class in another test module

Previously, if a submodule skipped test classes in an adjacent submodule (same
parent module), only the running submodule was imported and an error was thrown
because getattr would not find the submodule of the to-be-skipped class. Updated
cached_import in django/utils/module_loading.py to include a check for the skipped
submodule, and import it if it is not there.

Thanks to Tim Graham for reporting this bug
This commit is contained in:
jmcfee 2024-04-25 19:14:22 -04:00 committed by Jon McFee
parent 195d885ca0
commit a2e3eed53e
3 changed files with 10 additions and 0 deletions

View File

@ -527,6 +527,7 @@ answer newbie questions, and generally made Django that much better:
Jonathan Buchanan <jonathan.buchanan@gmail.com>
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
Jonathan Feignberg <jdf@pobox.com>
Jonathan McFee <jmcfee@umich.edu>
Jonathan Slenders
Jonny Park <jonnythebard9@gmail.com>
Jordan Bae <qoentlr37@gmail.com>

View File

@ -13,6 +13,11 @@ def cached_import(module_path, class_name):
and getattr(spec, "_initializing", False) is False
):
module = import_module(module_path)
if not hasattr(module, class_name):
try:
import_module(f"{module_path}.{class_name}")
except ImportError:
pass
return getattr(module, class_name)

View File

@ -133,6 +133,10 @@ class ModuleImportTests(SimpleTestCase):
cls = import_string("django.utils.module_loading.import_string")
self.assertEqual(cls, import_string)
import_string("utils_tests.test_module.main_module")
good_module = import_string("utils_tests.test_module.good_module")
self.assertEqual(good_module.content, "Good Module")
# Test exceptions raised
with self.assertRaises(ImportError):
import_string("no_dots_in_path")