summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
Diffstat (limited to 'django/test')
-rw-r--r--django/test/runner.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/django/test/runner.py b/django/test/runner.py
index d0367ba71e..ecae164d7f 100644
--- a/django/test/runner.py
+++ b/django/test/runner.py
@@ -1,6 +1,7 @@
import argparse
import ctypes
import faulthandler
+import functools
import hashlib
import io
import itertools
@@ -485,6 +486,16 @@ def _init_worker(
)
+def _safe_init_worker(init_worker, counter, *args, **kwargs):
+ try:
+ init_worker(counter, *args, **kwargs)
+ except Exception:
+ with counter.get_lock():
+ # Set a value that will not increment above zero any time soon.
+ counter.value = -1000
+ raise
+
+
def _run_subsuite(args):
"""
Run a suite of tests with a RemoteTestRunner and return a RemoteTestResult.
@@ -558,7 +569,7 @@ class ParallelTestSuite(unittest.TestSuite):
counter = multiprocessing.Value(ctypes.c_int, 0)
pool = multiprocessing.Pool(
processes=self.processes,
- initializer=self.init_worker.__func__,
+ initializer=functools.partial(_safe_init_worker, self.init_worker.__func__),
initargs=[
counter,
self.initial_settings,
@@ -585,7 +596,11 @@ class ParallelTestSuite(unittest.TestSuite):
try:
subsuite_index, events = test_results.next(timeout=0.1)
- except multiprocessing.TimeoutError:
+ except multiprocessing.TimeoutError as err:
+ if counter.value < 0:
+ err.add_note("ERROR: _init_worker failed, see prior traceback")
+ pool.close()
+ raise
continue
except StopIteration:
pool.close()