Skip to content

Commit 70108e3

Browse files
Joshua HermanJoshua Herman
Joshua Herman
authored and
Joshua Herman
committed
pythongh-82054: Implementing unittest sharding for asyncio
1 parent ef25feb commit 70108e3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Lib/test/libregrtest/runtest.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ def __str__(self) -> str:
143143
# set of tests that we don't want to be executed when using regrtest
144144
NOTTESTS = set()
145145

146+
#If these test directories are encountered recurse into them and treat each
147+
# test_ .py or dir as a separate test module. This can increase parallelism.
148+
# Beware this can't generally be done for any directory with sub-tests as the
149+
# __init__.py may do things which alter what tests are to be run.
150+
151+
SPLITTESTDIRS = {
152+
"test_asyncio",
153+
"test_compiler",
154+
}
146155

147156
# Storage of uncollectable objects
148157
FOUND_GARBAGE = []
@@ -158,16 +167,24 @@ def findtestdir(path=None):
158167
return path or os.path.dirname(os.path.dirname(__file__)) or os.curdir
159168

160169

161-
def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
170+
def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS, splittestdirs=SPLITTESTDIRS, base_mod=""):
162171
"""Return a list of all applicable test modules."""
163172
testdir = findtestdir(testdir)
164173
names = os.listdir(testdir)
165174
tests = []
166175
others = set(stdtests) | nottests
167176
for name in names:
168177
mod, ext = os.path.splitext(name)
169-
if mod[:5] == "test_" and ext in (".py", "") and mod not in others:
170-
tests.append(mod)
178+
if mod[:5] == "test_" and mod not in others:
179+
if mod in splittestdirs:
180+
subdir = os.path.join(testdir, mod)
181+
if len(base_mod):
182+
mod = f"{base_mod}.{mod}"
183+
else:
184+
mod = f"test.{mod}"
185+
tests.extend(findtests(subdir, [], nottests, splittestdirs, mod))
186+
elif ext in (".py", ""):
187+
tests.append(f"{base_mod}.{mod}" if len(base_mod) else mod)
171188
return stdtests + sorted(tests)
172189

173190

0 commit comments

Comments
 (0)