def test_get_max_test_processes_spawn( self, mocked_get_start_method, mocked_cpu_count, ): mocked_get_start_method.return_value = 'spawn' self.assertEqual(get_max_test_processes(), 1) with mock.patch.dict(os.environ, {'DJANGO_TEST_PROCESSES': '7'}): self.assertEqual(get_max_test_processes(), 1)
def test_get_max_test_processes_forkserver( self, mocked_get_start_method, mocked_cpu_count, ): mocked_get_start_method.return_value = "forkserver" self.assertEqual(get_max_test_processes(), 1) with mock.patch.dict(os.environ, {"DJANGO_TEST_PROCESSES": "7"}): self.assertEqual(get_max_test_processes(), 1)
def django_tests(verbosity, interactive, failfast, keepdb, reverse, test_labels, debug_sql, parallel, tags, exclude_tags, test_name_patterns, start_at, start_after, pdb, buffer, timing, shuffle): if parallel in {0, 'auto'}: max_parallel = get_max_test_processes() else: max_parallel = parallel if verbosity >= 1: msg = "Testing against Django installed in '%s'" % os.path.dirname( django.__file__) if max_parallel > 1: msg += " with up to %d processes" % max_parallel print(msg) test_labels, state = setup_run_tests(verbosity, start_at, start_after, test_labels) # Run the test suite, including the extra validation tests. if not hasattr(settings, 'TEST_RUNNER'): settings.TEST_RUNNER = 'django.test.runner.DiscoverRunner' if parallel in {0, 'auto'}: # This doesn't work before django.setup() on some databases. if all(conn.features.can_clone_databases for conn in connections.all()): parallel = max_parallel else: parallel = 1 TestRunner = get_runner(settings) test_runner = TestRunner( verbosity=verbosity, interactive=interactive, failfast=failfast, keepdb=keepdb, reverse=reverse, debug_sql=debug_sql, parallel=parallel, tags=tags, exclude_tags=exclude_tags, test_name_patterns=test_name_patterns, pdb=pdb, buffer=buffer, timing=timing, shuffle=shuffle, ) failures = test_runner.run_tests(test_labels) teardown_run_tests(state) return failures
def handle(self, *test_labels, **options): TestRunner = get_runner(settings, options['testrunner']) time_keeper = TimeKeeper() if options.get('timing', False) else NullTimeKeeper() parallel = options.get('parallel') if parallel == 'auto': options['parallel'] = get_max_test_processes() test_runner = TestRunner(**options) with time_keeper.timed('Total run'): failures = test_runner.run_tests(test_labels) time_keeper.print_results() if failures: sys.exit(1)
def test_get_max_test_processes_env_var(self, *mocked_objects): self.assertEqual(get_max_test_processes(), 7)