Skip to content

Commit 606fc35

Browse files
adamzapjacobtylerwalls
authored andcommitted
Fixed #36083 -- Ran system checks in ParallelTestSuite workers.
Workers created by ParallelTestSuite were not running system checks in the spawn multiprocessing mode. In general this is fine, but system checks can have side effects expected by tests. This patch runs system checks inside of _init_worker, which is only called by ParallelTestSuite.
1 parent 2063c88 commit 606fc35

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

django/test/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def _init_worker(
439439
used_aliases=None,
440440
):
441441
"""
442-
Switch to databases dedicated to this worker.
442+
Switch to databases dedicated to this worker and run system checks.
443443
444444
This helper lives at module-level because of the multiprocessing module's
445445
requirements.
@@ -463,6 +463,9 @@ def _init_worker(
463463
process_setup(*process_setup_args)
464464
django.setup()
465465
setup_test_environment(debug=debug_mode)
466+
call_command(
467+
"check", stdout=io.StringIO(), stderr=io.StringIO(), databases=used_aliases
468+
)
466469

467470
db_aliases = used_aliases if used_aliases is not None else connections
468471
for alias in db_aliases:

tests/test_runner/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ class Person(models.Model):
66
last_name = models.CharField(max_length=20)
77
friends = models.ManyToManyField("self")
88

9+
system_check_run_count = 0
10+
11+
@classmethod
12+
def check(cls, *args, **kwargs):
13+
cls.system_check_run_count += 1
14+
return super().check(**kwargs)
15+
916

1017
# A set of models that use a non-abstract inherited 'through' model.
1118
class ThroughBase(models.Model):

tests/test_runner/test_parallel.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from django.test import SimpleTestCase
99
from django.test.runner import ParallelTestSuite, RemoteTestResult
1010

11+
from . import models
12+
1113
try:
1214
import tblib.pickling_support
1315
except ImportError:
@@ -48,6 +50,9 @@ def test_subtest(self):
4850
with self.subTest(index=i):
4951
self.assertEqual(i, i)
5052

53+
def test_system_checks(self):
54+
self.assertEqual(models.Person.system_check_run_count, 1)
55+
5156

5257
class SampleFailingSubtest(SimpleTestCase):
5358
# This method name doesn't begin with "test" to prevent test discovery

0 commit comments

Comments
 (0)