From 39bb66baad1b98e0fa10d668a09154a0f5372b3d Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 4 Sep 2015 23:22:56 +0200 Subject: [PATCH] Made it easier to customize the parallel test runner. Subclass private APIs is marginally better than monkey-patching them, even if it doesn't make a big difference in practice. --- django/test/runner.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/django/test/runner.py b/django/test/runner.py index 2619fe4504..04ee14ec72 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -270,6 +270,10 @@ class ParallelTestSuite(unittest.TestSuite): that they have been run in parallel. """ + # In case someone wants to modify these in a subclass. + init_worker = _init_worker + run_subsuite = _run_subsuite + def __init__(self, suite, processes, failfast=False): self.subsuites = partition_suite_by_case(suite) self.processes = processes @@ -297,13 +301,13 @@ class ParallelTestSuite(unittest.TestSuite): counter = multiprocessing.Value(ctypes.c_int, 0) pool = multiprocessing.Pool( processes=self.processes, - initializer=_init_worker, + initializer=self.init_worker.__func__, initargs=[counter]) args = [ (index, subsuite, self.failfast) for index, subsuite in enumerate(self.subsuites) ] - test_results = pool.imap_unordered(_run_subsuite, args) + test_results = pool.imap_unordered(self.run_subsuite.__func__, args) while True: if result.shouldStop: @@ -339,6 +343,7 @@ class DiscoverRunner(object): """ test_suite = unittest.TestSuite + parallel_test_suite = ParallelTestSuite test_runner = unittest.TextTestRunner test_loader = unittest.defaultTestLoader reorder_by = (TestCase, SimpleTestCase) @@ -448,7 +453,7 @@ class DiscoverRunner(object): suite = reorder_suite(suite, self.reorder_by, self.reverse) if self.parallel > 1: - suite = ParallelTestSuite(suite, self.parallel, self.failfast) + suite = self.parallel_test_suite(suite, self.parallel, self.failfast) return suite