1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #31370 -- Added support for parallel tests with --buffer.

This commit is contained in:
Adam Johnson 2021-03-16 12:45:53 +00:00 committed by Mariusz Felisiak
parent e3bca22e7e
commit f6713cda89
3 changed files with 17 additions and 19 deletions

View File

@ -314,8 +314,9 @@ class RemoteTestRunner:
resultclass = RemoteTestResult
def __init__(self, failfast=False, resultclass=None):
def __init__(self, failfast=False, resultclass=None, buffer=False):
self.failfast = failfast
self.buffer = buffer
if resultclass is not None:
self.resultclass = resultclass
@ -323,6 +324,7 @@ class RemoteTestRunner:
result = self.resultclass()
unittest.registerResult(result)
result.failfast = self.failfast
result.buffer = self.buffer
test(result)
return result
@ -374,8 +376,8 @@ def _run_subsuite(args):
This helper lives at module-level and its arguments are wrapped in a tuple
because of the multiprocessing module's requirements.
"""
runner_class, subsuite_index, subsuite, failfast = args
runner = runner_class(failfast=failfast)
runner_class, subsuite_index, subsuite, failfast, buffer = args
runner = runner_class(failfast=failfast, buffer=buffer)
result = runner.run(subsuite)
return subsuite_index, result.events
@ -401,10 +403,11 @@ class ParallelTestSuite(unittest.TestSuite):
run_subsuite = _run_subsuite
runner_class = RemoteTestRunner
def __init__(self, suite, processes, failfast=False):
def __init__(self, suite, processes, failfast=False, buffer=False):
self.subsuites = partition_suite_by_case(suite)
self.processes = processes
self.failfast = failfast
self.buffer = buffer
super().__init__()
def run(self, result):
@ -429,7 +432,7 @@ class ParallelTestSuite(unittest.TestSuite):
initargs=[counter],
)
args = [
(self.runner_class, index, subsuite, self.failfast)
(self.runner_class, index, subsuite, self.failfast, self.buffer)
for index, subsuite in enumerate(self.subsuites)
]
test_results = pool.imap_unordered(self.run_subsuite.__func__, args)
@ -502,11 +505,6 @@ class DiscoverRunner:
if self.pdb and self.parallel > 1:
raise ValueError('You cannot use --pdb with parallel tests; pass --parallel=1 to use it.')
self.buffer = buffer
if self.buffer and self.parallel > 1:
raise ValueError(
'You cannot use -b/--buffer with parallel tests; pass '
'--parallel=1 to use it.'
)
self.test_name_patterns = None
self.time_keeper = TimeKeeper() if timing else NullTimeKeeper()
if test_name_patterns:
@ -635,7 +633,12 @@ class DiscoverRunner:
suite = self.test_suite(all_tests)
if self.parallel > 1:
parallel_suite = self.parallel_test_suite(suite, self.parallel, self.failfast)
parallel_suite = self.parallel_test_suite(
suite,
self.parallel,
self.failfast,
self.buffer,
)
# Since tests are distributed across processes on a per-TestCase
# basis, there's no need for more processes than TestCases.

View File

@ -258,6 +258,9 @@ Tests
serialized to allow usage of the
:ref:`serialized_rollback <test-case-serialized-rollback>` feature.
* Django test runner now supports a :option:`--buffer <test --buffer>` option
with parallel tests.
URLs
~~~~

View File

@ -269,14 +269,6 @@ class DiscoverRunnerTests(SimpleTestCase):
with self.assertRaisesMessage(ValueError, msg):
DiscoverRunner(pdb=True, parallel=2)
def test_buffer_with_parallel(self):
msg = (
'You cannot use -b/--buffer with parallel tests; pass '
'--parallel=1 to use it.'
)
with self.assertRaisesMessage(ValueError, msg):
DiscoverRunner(buffer=True, parallel=2)
def test_buffer_mode_test_pass(self):
runner = DiscoverRunner(buffer=True, verbose=0)
with captured_stdout() as stdout, captured_stderr() as stderr: