Skip to content

Commit fdcd488

Browse files
jonmcfee03timgraham
authored andcommitted
Fixed #35402 -- Fixed crash when DatabaseFeatures.django_test_skips references a class in another test module
1 parent 4635c44 commit fdcd488

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ answer newbie questions, and generally made Django that much better:
521521
Jonathan Buchanan <[email protected]>
522522
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
523523
Jonathan Feignberg <[email protected]>
524+
Jonathan McFee <[email protected]>
524525
Jonathan Slenders
525526
Jonny Park <[email protected]>
526527
Jordan Bae <[email protected]>

django/db/backends/base/creation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,19 @@ def mark_expected_failures_and_skips(self):
347347
for reason, tests in self.connection.features.django_test_skips.items():
348348
for test_name in tests:
349349
test_case_name, _, test_method_name = test_name.rpartition(".")
350+
if not test_method_name.startswith("test"):
351+
test_case_name = test_name
352+
test_method_name = None
350353
test_app = test_name.split(".")[0]
351354
# Importing a test app that isn't installed raises RuntimeError.
352355
if test_app in settings.INSTALLED_APPS:
353356
test_case = import_string(test_case_name)
354-
test_method = getattr(test_case, test_method_name)
355-
setattr(test_case, test_method_name, skip(reason)(test_method))
357+
if test_method_name:
358+
test_method = getattr(test_case, test_method_name)
359+
setattr(test_case, test_method_name, skip(reason)(test_method))
360+
else:
361+
setattr(test_case, "__unittest_skip__", True)
362+
setattr(test_case, "__unittest_skip_why__", reason)
356363

357364
def sql_table_creation_suffix(self):
358365
"""

tests/backends/base/test_creation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ def test_serialize_db_to_string_base_manager_with_prefetch_related(self):
269269

270270

271271
class SkipTestClass:
272-
def skip_function(self):
272+
def test_skip_function(self):
273273
pass
274274

275275

276-
def skip_test_function():
276+
def test_skip_test_function():
277277
pass
278278

279279

@@ -293,7 +293,7 @@ def test_mark_expected_failures_and_skips(self):
293293
"backends.base.test_creation.SkipTestClass",
294294
},
295295
"skip test function": {
296-
"backends.base.test_creation.skip_test_function",
296+
"backends.base.test_creation.test_skip_test_function",
297297
},
298298
}
299299
creation.mark_expected_failures_and_skips()
@@ -306,8 +306,8 @@ def test_mark_expected_failures_and_skips(self):
306306
SkipTestClass.__unittest_skip_why__,
307307
"skip test class",
308308
)
309-
self.assertIs(skip_test_function.__unittest_skip__, True)
309+
self.assertIs(test_skip_test_function.__unittest_skip__, True)
310310
self.assertEqual(
311-
skip_test_function.__unittest_skip_why__,
311+
test_skip_test_function.__unittest_skip_why__,
312312
"skip test function",
313313
)

0 commit comments

Comments
 (0)