Fixed #31370 -- Added support for parallel tests with --buffer.
This commit is contained in:
parent
e3bca22e7e
commit
f6713cda89
|
@ -314,8 +314,9 @@ class RemoteTestRunner:
|
||||||
|
|
||||||
resultclass = RemoteTestResult
|
resultclass = RemoteTestResult
|
||||||
|
|
||||||
def __init__(self, failfast=False, resultclass=None):
|
def __init__(self, failfast=False, resultclass=None, buffer=False):
|
||||||
self.failfast = failfast
|
self.failfast = failfast
|
||||||
|
self.buffer = buffer
|
||||||
if resultclass is not None:
|
if resultclass is not None:
|
||||||
self.resultclass = resultclass
|
self.resultclass = resultclass
|
||||||
|
|
||||||
|
@ -323,6 +324,7 @@ class RemoteTestRunner:
|
||||||
result = self.resultclass()
|
result = self.resultclass()
|
||||||
unittest.registerResult(result)
|
unittest.registerResult(result)
|
||||||
result.failfast = self.failfast
|
result.failfast = self.failfast
|
||||||
|
result.buffer = self.buffer
|
||||||
test(result)
|
test(result)
|
||||||
return 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
|
This helper lives at module-level and its arguments are wrapped in a tuple
|
||||||
because of the multiprocessing module's requirements.
|
because of the multiprocessing module's requirements.
|
||||||
"""
|
"""
|
||||||
runner_class, subsuite_index, subsuite, failfast = args
|
runner_class, subsuite_index, subsuite, failfast, buffer = args
|
||||||
runner = runner_class(failfast=failfast)
|
runner = runner_class(failfast=failfast, buffer=buffer)
|
||||||
result = runner.run(subsuite)
|
result = runner.run(subsuite)
|
||||||
return subsuite_index, result.events
|
return subsuite_index, result.events
|
||||||
|
|
||||||
|
@ -401,10 +403,11 @@ class ParallelTestSuite(unittest.TestSuite):
|
||||||
run_subsuite = _run_subsuite
|
run_subsuite = _run_subsuite
|
||||||
runner_class = RemoteTestRunner
|
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.subsuites = partition_suite_by_case(suite)
|
||||||
self.processes = processes
|
self.processes = processes
|
||||||
self.failfast = failfast
|
self.failfast = failfast
|
||||||
|
self.buffer = buffer
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def run(self, result):
|
def run(self, result):
|
||||||
|
@ -429,7 +432,7 @@ class ParallelTestSuite(unittest.TestSuite):
|
||||||
initargs=[counter],
|
initargs=[counter],
|
||||||
)
|
)
|
||||||
args = [
|
args = [
|
||||||
(self.runner_class, index, subsuite, self.failfast)
|
(self.runner_class, index, subsuite, self.failfast, self.buffer)
|
||||||
for index, subsuite in enumerate(self.subsuites)
|
for index, subsuite in enumerate(self.subsuites)
|
||||||
]
|
]
|
||||||
test_results = pool.imap_unordered(self.run_subsuite.__func__, args)
|
test_results = pool.imap_unordered(self.run_subsuite.__func__, args)
|
||||||
|
@ -502,11 +505,6 @@ class DiscoverRunner:
|
||||||
if self.pdb and self.parallel > 1:
|
if self.pdb and self.parallel > 1:
|
||||||
raise ValueError('You cannot use --pdb with parallel tests; pass --parallel=1 to use it.')
|
raise ValueError('You cannot use --pdb with parallel tests; pass --parallel=1 to use it.')
|
||||||
self.buffer = buffer
|
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.test_name_patterns = None
|
||||||
self.time_keeper = TimeKeeper() if timing else NullTimeKeeper()
|
self.time_keeper = TimeKeeper() if timing else NullTimeKeeper()
|
||||||
if test_name_patterns:
|
if test_name_patterns:
|
||||||
|
@ -635,7 +633,12 @@ class DiscoverRunner:
|
||||||
suite = self.test_suite(all_tests)
|
suite = self.test_suite(all_tests)
|
||||||
|
|
||||||
if self.parallel > 1:
|
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
|
# Since tests are distributed across processes on a per-TestCase
|
||||||
# basis, there's no need for more processes than TestCases.
|
# basis, there's no need for more processes than TestCases.
|
||||||
|
|
|
@ -258,6 +258,9 @@ Tests
|
||||||
serialized to allow usage of the
|
serialized to allow usage of the
|
||||||
:ref:`serialized_rollback <test-case-serialized-rollback>` feature.
|
:ref:`serialized_rollback <test-case-serialized-rollback>` feature.
|
||||||
|
|
||||||
|
* Django test runner now supports a :option:`--buffer <test --buffer>` option
|
||||||
|
with parallel tests.
|
||||||
|
|
||||||
URLs
|
URLs
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
|
|
|
@ -269,14 +269,6 @@ class DiscoverRunnerTests(SimpleTestCase):
|
||||||
with self.assertRaisesMessage(ValueError, msg):
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
DiscoverRunner(pdb=True, parallel=2)
|
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):
|
def test_buffer_mode_test_pass(self):
|
||||||
runner = DiscoverRunner(buffer=True, verbose=0)
|
runner = DiscoverRunner(buffer=True, verbose=0)
|
||||||
with captured_stdout() as stdout, captured_stderr() as stderr:
|
with captured_stdout() as stdout, captured_stderr() as stderr:
|
||||||
|
|
Loading…
Reference in New Issue