Skip to content

Commit

Permalink
Refs #35844 -- Fixed tests for test --parallel option on Python 3.14+.
Browse files Browse the repository at this point in the history
"forkserver" is the new default on POSIX systems, and Django doesn't
support parallel tests with "forkserver":

python/cpython@b65f2cd
  • Loading branch information
felixxm authored Oct 24, 2024
1 parent 2d61216 commit 34066d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_runner/test_discover_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_runner/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def test_durations_lt_py312(self):
@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(
Expand All @@ -515,6 +516,7 @@ def test_parallel_default(self, *mocked_objects):
)
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(
Expand Down Expand Up @@ -550,12 +552,14 @@ def test_no_parallel_spawn(self, *mocked_objects):
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(
Expand All @@ -565,6 +569,7 @@ def test_django_test_processes_env_non_int(self, *mocked_objects):
)

@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):
Expand Down

0 comments on commit 34066d6

Please sign in to comment.