Skip to content

Commit b2cea8f

Browse files
vstinnermiss-islington
authored andcommitted
pythongh-108388: Split test_multiprocessing_spawn (pythonGH-108396)
Split test_multiprocessing_fork, test_multiprocessing_forkserver and test_multiprocessing_spawn into test packages. Each package is made of 4 sub-tests: processes, threads, manager and misc. It allows running more tests in parallel and so reduce the total test duration. (cherry picked from commit aa9a359) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent ca8da71 commit b2cea8f

19 files changed

+117
-27
lines changed

Lib/test/_test_multiprocessing.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -6080,7 +6080,8 @@ class ThreadsMixin(BaseMixin):
60806080
# Functions used to create test cases from the base ones in this module
60816081
#
60826082

6083-
def install_tests_in_module_dict(remote_globs, start_method):
6083+
def install_tests_in_module_dict(remote_globs, start_method,
6084+
only_type=None, exclude_types=False):
60846085
__module__ = remote_globs['__name__']
60856086
local_globs = globals()
60866087
ALL_TYPES = {'processes', 'threads', 'manager'}
@@ -6093,6 +6094,10 @@ def install_tests_in_module_dict(remote_globs, start_method):
60936094
continue
60946095
assert set(base.ALLOWED_TYPES) <= ALL_TYPES, base.ALLOWED_TYPES
60956096
for type_ in base.ALLOWED_TYPES:
6097+
if only_type and type_ != only_type:
6098+
continue
6099+
if exclude_types:
6100+
continue
60966101
newname = 'With' + type_.capitalize() + name[1:]
60976102
Mixin = local_globs[type_.capitalize() + 'Mixin']
60986103
class Temp(base, Mixin, unittest.TestCase):
@@ -6103,6 +6108,9 @@ class Temp(base, Mixin, unittest.TestCase):
61036108
Temp.__module__ = __module__
61046109
remote_globs[newname] = Temp
61056110
elif issubclass(base, unittest.TestCase):
6111+
if only_type:
6112+
continue
6113+
61066114
class Temp(base, object):
61076115
pass
61086116
Temp.__name__ = Temp.__qualname__ = name

Lib/test/libregrtest/runtest.py

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ def set_env_changed(self):
141141

142142
SPLITTESTDIRS = {
143143
"test_asyncio",
144+
"test_multiprocessing_fork",
145+
"test_multiprocessing_forkserver",
146+
"test_multiprocessing_spawn",
144147
}
145148

146149
# Storage of uncollectable objects
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import unittest
2-
import test._test_multiprocessing
3-
1+
import os.path
42
import sys
3+
import unittest
54
from test import support
65

76
if support.PGO:
@@ -13,7 +12,5 @@
1312
if sys.platform == 'darwin':
1413
raise unittest.SkipTest("test may crash on macOS (bpo-33725)")
1514

16-
test._test_multiprocessing.install_tests_in_module_dict(globals(), 'fork')
17-
18-
if __name__ == '__main__':
19-
unittest.main()
15+
def load_tests(*args):
16+
return support.load_package_tests(os.path.dirname(__file__), *args)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'fork', only_type="manager")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'fork', exclude_types=True)
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'fork', only_type="processes")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'fork', only_type="threads")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import unittest
2-
import test._test_multiprocessing
3-
1+
import os.path
42
import sys
3+
import unittest
54
from test import support
65

76
if support.PGO:
@@ -10,7 +9,5 @@
109
if sys.platform == "win32":
1110
raise unittest.SkipTest("forkserver is not available on Windows")
1211

13-
test._test_multiprocessing.install_tests_in_module_dict(globals(), 'forkserver')
14-
15-
if __name__ == '__main__':
16-
unittest.main()
12+
def load_tests(*args):
13+
return support.load_package_tests(os.path.dirname(__file__), *args)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'forkserver', only_type="manager")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'forkserver', exclude_types=True)
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'forkserver', only_type="processes")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'forkserver', only_type="threads")
5+
6+
if __name__ == '__main__':
7+
unittest.main()

Lib/test/test_multiprocessing_spawn.py

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os.path
2+
import unittest
3+
from test import support
4+
5+
if support.PGO:
6+
raise unittest.SkipTest("test is not helpful for PGO")
7+
8+
def load_tests(*args):
9+
return support.load_package_tests(os.path.dirname(__file__), *args)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'spawn', only_type="manager")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'spawn', exclude_types=True)
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'spawn', only_type="processes")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
from test._test_multiprocessing import install_tests_in_module_dict
3+
4+
install_tests_in_module_dict(globals(), 'spawn', only_type="threads")
5+
6+
if __name__ == '__main__':
7+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Split test_multiprocessing_fork, test_multiprocessing_forkserver and
2+
test_multiprocessing_spawn into test packages. Each package is made of 4
3+
sub-tests: processes, threads, manager and misc. It allows running more tests
4+
in parallel and so reduce the total test duration. Patch by Victor Stinner.

0 commit comments

Comments
 (0)