From 34066d6cf3d66b8a3c7fac86912455dbb2ed0ed6 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 24 Oct 2024 16:41:37 +0200 Subject: [PATCH] Refs #35844 -- Fixed tests for test --parallel option on Python 3.14+. "forkserver" is the new default on POSIX systems, and Django doesn't support parallel tests with "forkserver": https://github.com/python/cpython/commit/b65f2cdfa77d8d12c213aec663ddaaa30d75a4b2 --- tests/test_runner/test_discover_runner.py | 1 + tests/test_runner/tests.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py index a845f6dd67..4f13cceeff 100644 --- a/tests/test_runner/test_discover_runner.py +++ b/tests/test_runner/test_discover_runner.py @@ -45,6 +45,7 @@ def change_loader_patterns(patterns): @mock.patch.dict(os.environ, {}, clear=True) @mock.patch.object(multiprocessing, "cpu_count", return_value=12) # Python 3.8 on macOS defaults to 'spawn' mode. +# Python 3.14 on POSIX systems defaults to 'forkserver' mode. @mock.patch.object(multiprocessing, "get_start_method", return_value="fork") class DiscoverRunnerParallelArgumentTests(SimpleTestCase): def get_parser(self): diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index b900ff69ea..fba8dd3b6f 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -506,6 +506,7 @@ class ManageCommandTests(unittest.TestCase): @mock.patch.dict(os.environ, {}, clear=True) @mock.patch.object(multiprocessing, "cpu_count", return_value=12) class ManageCommandParallelTests(SimpleTestCase): + @mock.patch.object(multiprocessing, "get_start_method", return_value="fork") def test_parallel_default(self, *mocked_objects): with captured_stderr() as stderr: call_command( @@ -515,6 +516,7 @@ class ManageCommandParallelTests(SimpleTestCase): ) self.assertIn("parallel=12", stderr.getvalue()) + @mock.patch.object(multiprocessing, "get_start_method", return_value="fork") def test_parallel_auto(self, *mocked_objects): with captured_stderr() as stderr: call_command( @@ -550,12 +552,14 @@ class ManageCommandParallelTests(SimpleTestCase): self.assertEqual(stderr.getvalue(), "") @mock.patch.dict(os.environ, {"DJANGO_TEST_PROCESSES": "7"}) + @mock.patch.object(multiprocessing, "get_start_method", return_value="fork") def test_no_parallel_django_test_processes_env(self, *mocked_objects): with captured_stderr() as stderr: call_command("test", testrunner="test_runner.tests.MockTestRunner") self.assertEqual(stderr.getvalue(), "") @mock.patch.dict(os.environ, {"DJANGO_TEST_PROCESSES": "invalid"}) + @mock.patch.object(multiprocessing, "get_start_method", return_value="fork") def test_django_test_processes_env_non_int(self, *mocked_objects): with self.assertRaises(ValueError): call_command( @@ -565,6 +569,7 @@ class ManageCommandParallelTests(SimpleTestCase): ) @mock.patch.dict(os.environ, {"DJANGO_TEST_PROCESSES": "7"}) + @mock.patch.object(multiprocessing, "get_start_method", return_value="fork") def test_django_test_processes_parallel_default(self, *mocked_objects): for parallel in ["--parallel", "--parallel=auto"]: with self.subTest(parallel=parallel):