summaryrefslogtreecommitdiff
path: root/tests/test_runner
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-05-19 10:20:51 +0200
committerGitHub <noreply@github.com>2022-05-19 10:20:51 +0200
commit41c4cb253c137edf5a96b7408ea55d57d6e0602a (patch)
tree7c357b93c894375e2bd37d35cd13ee5ed4078191 /tests/test_runner
parent981c23c0ccbcaa155a80f894fd9e832beaab661d (diff)
Fixed #33719 -- Fixed test command crash when running in parallel.
Thanks Pēteris Caune for the report. Regression in 3b3f38b3b09b0f2373e51406ecb8c9c45d36aebc.
Diffstat (limited to 'tests/test_runner')
-rw-r--r--tests/test_runner/tests.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py
index c022a6fb86..b3c7cc5a55 100644
--- a/tests/test_runner/tests.py
+++ b/tests/test_runner/tests.py
@@ -19,6 +19,7 @@ from django.test import SimpleTestCase, TransactionTestCase, skipUnlessDBFeature
from django.test.runner import (
DiscoverRunner,
Shuffler,
+ _init_worker,
reorder_test_bin,
reorder_tests,
shuffle_tests,
@@ -684,6 +685,46 @@ class NoInitializeSuiteTestRunnerTests(SimpleTestCase):
)
+class TestRunnerInitializerTests(SimpleTestCase):
+
+ # Raise an exception to don't actually run tests.
+ @mock.patch.object(
+ multiprocessing, "Pool", side_effect=Exception("multiprocessing.Pool()")
+ )
+ def test_no_initialize_suite_test_runner(self, mocked_pool):
+ class StubTestRunner(DiscoverRunner):
+ def setup_test_environment(self, **kwargs):
+ return
+
+ def setup_databases(self, **kwargs):
+ return
+
+ def run_checks(self, databases):
+ return
+
+ def teardown_databases(self, old_config, **kwargs):
+ return
+
+ def teardown_test_environment(self, **kwargs):
+ return
+
+ def run_suite(self, suite, **kwargs):
+ kwargs = self.get_test_runner_kwargs()
+ runner = self.test_runner(**kwargs)
+ return runner.run(suite)
+
+ runner = StubTestRunner(verbosity=0, interactive=False, parallel=2)
+ with self.assertRaisesMessage(Exception, "multiprocessing.Pool()"):
+ runner.run_tests(
+ [
+ "test_runner_apps.sample.tests_sample.TestDjangoTestCase",
+ "test_runner_apps.simple.tests",
+ ]
+ )
+ # Initializer must be a function.
+ self.assertIs(mocked_pool.call_args.kwargs["initializer"], _init_worker)
+
+
class Ticket17477RegressionTests(AdminScriptTestCase):
def setUp(self):
super().setUp()