Refs #31621 -- Added more tests for test --parallel option.
This commit is contained in:
parent
795051b2b0
commit
7e38a8d66f
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
import unittest.loader
|
import unittest.loader
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
@ -36,6 +37,40 @@ def change_loader_patterns(patterns):
|
||||||
DiscoverRunner.test_loader.testNamePatterns = original_patterns
|
DiscoverRunner.test_loader.testNamePatterns = original_patterns
|
||||||
|
|
||||||
|
|
||||||
|
# Isolate from the real environment.
|
||||||
|
@mock.patch.dict(os.environ, {}, clear=True)
|
||||||
|
@mock.patch.object(multiprocessing, 'cpu_count', return_value=12)
|
||||||
|
# Python 3.8 on macOS defaults to 'spawn' mode.
|
||||||
|
@mock.patch.object(multiprocessing, 'get_start_method', return_value='fork')
|
||||||
|
class DiscoverRunnerParallelArgumentTests(SimpleTestCase):
|
||||||
|
def get_parser(self):
|
||||||
|
parser = ArgumentParser()
|
||||||
|
DiscoverRunner.add_arguments(parser)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def test_parallel_default(self, *mocked_objects):
|
||||||
|
result = self.get_parser().parse_args([])
|
||||||
|
self.assertEqual(result.parallel, 1)
|
||||||
|
|
||||||
|
def test_parallel_flag(self, *mocked_objects):
|
||||||
|
result = self.get_parser().parse_args(['--parallel'])
|
||||||
|
self.assertEqual(result.parallel, 12)
|
||||||
|
|
||||||
|
def test_parallel_count(self, *mocked_objects):
|
||||||
|
result = self.get_parser().parse_args(['--parallel', '17'])
|
||||||
|
self.assertEqual(result.parallel, 17)
|
||||||
|
|
||||||
|
@mock.patch.dict(os.environ, {'DJANGO_TEST_PROCESSES': 'typo'})
|
||||||
|
def test_parallel_env_var_non_int(self, *mocked_objects):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
self.get_parser().parse_args([])
|
||||||
|
|
||||||
|
def test_parallel_spawn(self, mocked_get_start_method, mocked_cpu_count):
|
||||||
|
mocked_get_start_method.return_value = 'spawn'
|
||||||
|
result = self.get_parser().parse_args(['--parallel'])
|
||||||
|
self.assertEqual(result.parallel, 1)
|
||||||
|
|
||||||
|
|
||||||
class DiscoverRunnerTests(SimpleTestCase):
|
class DiscoverRunnerTests(SimpleTestCase):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue