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>
This commit is contained in:
David Smith 2022-02-12 20:40:12 +00:00 committed by Carlton Gibson
parent 3eaba13a47
commit 3b3f38b3b0
12 changed files with 161 additions and 23 deletions

View file

@ -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: