summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Zapletal <adamzap@gmail.com>2025-01-18 16:22:10 -0600
committerJacob Walls <jacobtylerwalls@gmail.com>2025-09-16 21:57:22 -0400
commit606fc352799e372928fa2c978ab99f0fb6d6017c (patch)
tree789edf713bd71ab9ad5c4e1bc0acafba380c0734
parent2063c88c34566f46ad120c5b37c9926ffd3f10a6 (diff)
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.
-rw-r--r--django/test/runner.py5
-rw-r--r--tests/test_runner/models.py7
-rw-r--r--tests/test_runner/test_parallel.py5
3 files changed, 16 insertions, 1 deletions
diff --git a/django/test/runner.py b/django/test/runner.py
index 1bfeca03af..8902dea3e0 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -439,7 +439,7 @@ def _init_worker(
used_aliases=None,
):
"""
- Switch to databases dedicated to this worker.
+ Switch to databases dedicated to this worker and run system checks.
This helper lives at module-level because of the multiprocessing module's
requirements.
@@ -463,6 +463,9 @@ def _init_worker(
process_setup(*process_setup_args)
django.setup()
setup_test_environment(debug=debug_mode)
+ call_command(
+ "check", stdout=io.StringIO(), stderr=io.StringIO(), databases=used_aliases
+ )
db_aliases = used_aliases if used_aliases is not None else connections
for alias in db_aliases:
diff --git a/tests/test_runner/models.py b/tests/test_runner/models.py
index 80bf8dd8c7..54ec5e2b3d 100644
--- a/tests/test_runner/models.py
+++ b/tests/test_runner/models.py
@@ -6,6 +6,13 @@ class Person(models.Model):
last_name = models.CharField(max_length=20)
friends = models.ManyToManyField("self")
+ system_check_run_count = 0
+
+ @classmethod
+ def check(cls, *args, **kwargs):
+ cls.system_check_run_count += 1
+ return super().check(**kwargs)
+
# A set of models that use a non-abstract inherited 'through' model.
class ThroughBase(models.Model):
diff --git a/tests/test_runner/test_parallel.py b/tests/test_runner/test_parallel.py
index 3af0fbf2f9..f344f1a2db 100644
--- a/tests/test_runner/test_parallel.py
+++ b/tests/test_runner/test_parallel.py
@@ -8,6 +8,8 @@ from unittest.suite import TestSuite, _ErrorHolder
from django.test import SimpleTestCase
from django.test.runner import ParallelTestSuite, RemoteTestResult
+from . import models
+
try:
import tblib.pickling_support
except ImportError:
@@ -48,6 +50,9 @@ class ParallelTestRunnerTest(SimpleTestCase):
with self.subTest(index=i):
self.assertEqual(i, i)
+ def test_system_checks(self):
+ self.assertEqual(models.Person.system_check_run_count, 1)
+
class SampleFailingSubtest(SimpleTestCase):
# This method name doesn't begin with "test" to prevent test discovery