diff --git a/django/test/runner.py b/django/test/runner.py index f2a91373b1..6bcf4111df 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -398,6 +398,7 @@ def _init_worker( serialized_contents=None, process_setup=None, process_setup_args=None, + debug_mode=None, ): """ Switch to databases dedicated to this worker. @@ -420,7 +421,7 @@ def _init_worker( process_setup_args = () process_setup(*process_setup_args) django.setup() - setup_test_environment() + setup_test_environment(debug=debug_mode) for alias in connections: connection = connections[alias] @@ -473,10 +474,13 @@ class ParallelTestSuite(unittest.TestSuite): run_subsuite = _run_subsuite runner_class = RemoteTestRunner - def __init__(self, subsuites, processes, failfast=False, buffer=False): + def __init__( + self, subsuites, processes, failfast=False, debug_mode=False, buffer=False + ): self.subsuites = subsuites self.processes = processes self.failfast = failfast + self.debug_mode = debug_mode self.buffer = buffer self.initial_settings = None self.serialized_contents = None @@ -508,6 +512,7 @@ class ParallelTestSuite(unittest.TestSuite): self.serialized_contents, self.process_setup.__func__, self.process_setup_args, + self.debug_mode, ], ) args = [ @@ -933,6 +938,7 @@ class DiscoverRunner: subsuites, processes, self.failfast, + self.debug_mode, self.buffer, ) return suite diff --git a/docs/releases/4.1.2.txt b/docs/releases/4.1.2.txt index 47b53f0e8b..434bc5f587 100644 --- a/docs/releases/4.1.2.txt +++ b/docs/releases/4.1.2.txt @@ -31,3 +31,7 @@ Bugfixes * Fixed a regression in Django 4.1 where the app registry was not populated when running parallel tests with the ``multiprocessing`` start method ``spawn`` (:ticket:`34010`). + +* Fixed a regression in Django 4.1 where the ``--debug-mode`` argument to + ``test`` did not work when running parallel tests with the + ``multiprocessing`` start method ``spawn`` (:ticket:`34010`). diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index b3c7cc5a55..30ea4ea670 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -713,7 +713,9 @@ class TestRunnerInitializerTests(SimpleTestCase): runner = self.test_runner(**kwargs) return runner.run(suite) - runner = StubTestRunner(verbosity=0, interactive=False, parallel=2) + runner = StubTestRunner( + verbosity=0, interactive=False, parallel=2, debug_mode=True + ) with self.assertRaisesMessage(Exception, "multiprocessing.Pool()"): runner.run_tests( [ @@ -723,6 +725,9 @@ class TestRunnerInitializerTests(SimpleTestCase): ) # Initializer must be a function. self.assertIs(mocked_pool.call_args.kwargs["initializer"], _init_worker) + initargs = mocked_pool.call_args.kwargs["initargs"] + self.assertEqual(len(initargs), 6) + self.assertEqual(initargs[5], True) # debug_mode class Ticket17477RegressionTests(AdminScriptTestCase):