diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-05-19 10:20:51 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-05-19 10:21:39 +0200 |
| commit | 2dd646e935d5ffa2289deb24e2a9a753010eeb82 (patch) | |
| tree | b2f5a7ffaceffb5bca273abfe7a7d06e9c9cd7f8 /django/test | |
| parent | 820b4e565a06eddacf9a8038dd7b83784c6e99da (diff) | |
[4.1.x] Fixed #33719 -- Fixed test command crash when running in parallel.
Thanks Pēteris Caune for the report.
Regression in 3b3f38b3b09b0f2373e51406ecb8c9c45d36aebc.
Backport of 41c4cb253c137edf5a96b7408ea55d57d6e0602a from main
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/runner.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/django/test/runner.py b/django/test/runner.py index fe30d2289b..55d902bb09 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -419,7 +419,10 @@ def _init_worker( start_method = multiprocessing.get_start_method() if start_method == "spawn": - process_setup(*process_setup_args) + if process_setup and callable(process_setup): + if process_setup_args is None: + process_setup_args = () + process_setup(*process_setup_args) setup_test_environment() for alias in connections: @@ -465,6 +468,7 @@ class ParallelTestSuite(unittest.TestSuite): # In case someone wants to modify these in a subclass. init_worker = _init_worker + process_setup_args = () run_subsuite = _run_subsuite runner_class = RemoteTestRunner @@ -477,6 +481,14 @@ class ParallelTestSuite(unittest.TestSuite): self.serialized_contents = None super().__init__() + def process_setup(self, *args): + """ + Stub method to simplify run() implementation. "self" is never actually + passed because a function implementing this method (__func__) is + always used, not the method itself. + """ + pass + def run(self, result): """ Distribute test cases across workers. @@ -496,11 +508,13 @@ class ParallelTestSuite(unittest.TestSuite): counter = multiprocessing.Value(ctypes.c_int, 0) pool = multiprocessing.Pool( processes=self.processes, - initializer=self.init_worker, + initializer=self.init_worker.__func__, initargs=[ counter, self.initial_settings, self.serialized_contents, + self.process_setup.__func__, + self.process_setup_args, ], ) args = [ |
