summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-05-19 10:20:51 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-05-19 10:21:39 +0200
commit2dd646e935d5ffa2289deb24e2a9a753010eeb82 (patch)
treeb2f5a7ffaceffb5bca273abfe7a7d06e9c9cd7f8 /tests
parent820b4e565a06eddacf9a8038dd7b83784c6e99da (diff)
[4.1.x] Fixed #33719 -- Fixed test command crash when running in parallel.
Thanks Pēteris Caune for the report. Regression in 3b3f38b3b09b0f2373e51406ecb8c9c45d36aebc. Backport of 41c4cb253c137edf5a96b7408ea55d57d6e0602a from main
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runtests.py10
-rw-r--r--tests/test_runner/tests.py41
2 files changed, 44 insertions, 7 deletions
diff --git a/tests/runtests.py b/tests/runtests.py
index e5adb902c3..bf8c79b231 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -11,7 +11,6 @@ import subprocess
import sys
import tempfile
import warnings
-from functools import partial
from pathlib import Path
try:
@@ -26,7 +25,7 @@ else:
from django.core.exceptions import ImproperlyConfigured
from django.db import connection, connections
from django.test import TestCase, TransactionTestCase
- from django.test.runner import _init_worker, get_max_test_processes, parallel_type
+ from django.test.runner import get_max_test_processes, parallel_type
from django.test.selenium import SeleniumTestCaseBase
from django.test.utils import NullTimeKeeper, TimeKeeper, get_runner
from django.utils.deprecation import RemovedInDjango50Warning
@@ -401,11 +400,8 @@ def django_tests(
parallel = 1
TestRunner = get_runner(settings)
- TestRunner.parallel_test_suite.init_worker = partial(
- _init_worker,
- process_setup=setup_run_tests,
- process_setup_args=process_setup_args,
- )
+ TestRunner.parallel_test_suite.process_setup = setup_run_tests
+ TestRunner.parallel_test_suite.process_setup_args = process_setup_args
test_runner = TestRunner(
verbosity=verbosity,
interactive=interactive,
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
index c022a6fb86..b3c7cc5a55 100644
--- a/tests/test_runner/tests.py
+++ b/tests/test_runner/tests.py
@@ -19,6 +19,7 @@ from django.test import SimpleTestCase, TransactionTestCase, skipUnlessDBFeature
from django.test.runner import (
DiscoverRunner,
Shuffler,
+ _init_worker,
reorder_test_bin,
reorder_tests,
shuffle_tests,
@@ -684,6 +685,46 @@ class NoInitializeSuiteTestRunnerTests(SimpleTestCase):
)
+class TestRunnerInitializerTests(SimpleTestCase):
+
+ # Raise an exception to don't actually run tests.
+ @mock.patch.object(
+ multiprocessing, "Pool", side_effect=Exception("multiprocessing.Pool()")
+ )
+ def test_no_initialize_suite_test_runner(self, mocked_pool):
+ class StubTestRunner(DiscoverRunner):
+ def setup_test_environment(self, **kwargs):
+ return
+
+ def setup_databases(self, **kwargs):
+ return
+
+ def run_checks(self, databases):
+ return
+
+ def teardown_databases(self, old_config, **kwargs):
+ return
+
+ def teardown_test_environment(self, **kwargs):
+ return
+
+ def run_suite(self, suite, **kwargs):
+ kwargs = self.get_test_runner_kwargs()
+ runner = self.test_runner(**kwargs)
+ return runner.run(suite)
+
+ runner = StubTestRunner(verbosity=0, interactive=False, parallel=2)
+ with self.assertRaisesMessage(Exception, "multiprocessing.Pool()"):
+ runner.run_tests(
+ [
+ "test_runner_apps.sample.tests_sample.TestDjangoTestCase",
+ "test_runner_apps.simple.tests",
+ ]
+ )
+ # Initializer must be a function.
+ self.assertIs(mocked_pool.call_args.kwargs["initializer"], _init_worker)
+
+
class Ticket17477RegressionTests(AdminScriptTestCase):
def setUp(self):
super().setUp()