diff options
author | David Smith <smithdc@gmail.com> | 2022-02-12 20:40:12 +0000 |
---|---|---|
committer | Carlton Gibson <carlton@noumenal.es> | 2022-03-15 16:23:55 +0100 |
commit | 3b3f38b3b09b0f2373e51406ecb8c9c45d36aebc (patch) | |
tree | 8ab2c436451318223606470fcdc23b6dc690da20 /tests/runtests.py | |
parent | 3eaba13a476c14b75429ba34180184b81997b33a (diff) | |
download | django-3b3f38b3b09b0f2373e51406ecb8c9c45d36aebc.tar.gz |
Fixed #31169 -- Adapted the parallel test runner to use spawn.
Co-authored-by: Valz <ahmadahussein0@gmail.com>
Co-authored-by: Nick Pope <nick@nickpope.me.uk>
Diffstat (limited to 'tests/runtests.py')
-rwxr-xr-x | tests/runtests.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/runtests.py b/tests/runtests.py index 330c8abd04..e3a60d777b 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -3,6 +3,7 @@ import argparse import atexit import copy import gc +import multiprocessing import os import shutil import socket @@ -10,6 +11,7 @@ import subprocess import sys import tempfile import warnings +from functools import partial from pathlib import Path try: @@ -24,7 +26,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 get_max_test_processes, parallel_type + from django.test.runner import _init_worker, 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 @@ -382,7 +384,8 @@ def django_tests( msg += " with up to %d processes" % max_parallel print(msg) - test_labels, state = setup_run_tests(verbosity, start_at, start_after, test_labels) + process_setup_args = (verbosity, start_at, start_after, test_labels) + test_labels, state = setup_run_tests(*process_setup_args) # Run the test suite, including the extra validation tests. if not hasattr(settings, "TEST_RUNNER"): settings.TEST_RUNNER = "django.test.runner.DiscoverRunner" @@ -395,6 +398,11 @@ 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, + ) test_runner = TestRunner( verbosity=verbosity, interactive=interactive, @@ -718,6 +726,11 @@ if __name__ == "__main__": options.settings = os.environ["DJANGO_SETTINGS_MODULE"] if options.selenium: + if multiprocessing.get_start_method() == "spawn" and options.parallel != 1: + parser.error( + "You cannot use --selenium with parallel tests on this system. " + "Pass --parallel=1 to use --selenium." + ) if not options.tags: options.tags = ["selenium"] elif "selenium" not in options.tags: |