mirror of
https://github.com/zulip/zulip.git
synced 2025-10-26 17:43:58 +00:00
test_runner: Monkey-patch to allow using multiprocessing in tests.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
f751acbec5
commit
73eb0aa891
@@ -1,9 +1,10 @@
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
from functools import partial
|
||||
from multiprocessing.sharedctypes import Synchronized
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union, cast
|
||||
from unittest import TestLoader, TestSuite, runner
|
||||
from unittest.result import TestResult
|
||||
|
||||
@@ -122,6 +123,15 @@ def run_subsuite(args: SubsuiteArgs) -> Tuple[int, Any]:
|
||||
process_instrumented_calls(partial(result.addInstrumentation, None))
|
||||
return subsuite_index, result.events
|
||||
|
||||
# Monkey-patch django.test.runner to allow using multiprocessing
|
||||
# inside tests without a “daemonic processes are not allowed to have
|
||||
# children” error.
|
||||
class NoDaemonContext(multiprocessing.context.ForkContext):
|
||||
class Process(multiprocessing.context.ForkProcess):
|
||||
daemon = cast(bool, property(lambda self: False, lambda self, value: None))
|
||||
|
||||
django_runner.multiprocessing = NoDaemonContext()
|
||||
|
||||
def destroy_test_databases(worker_id: Optional[int]=None) -> None:
|
||||
for alias in connections:
|
||||
connection = connections[alias]
|
||||
|
||||
Reference in New Issue
Block a user