Skip to content

Commit 174e9da

Browse files
authored
pythongh-108388: regrtest splits test_asyncio package (python#108393)
Currently, test_asyncio package is only splitted into sub-tests when using command "./python -m test". With this change, it's also splitted when passing it on the command line: "./python -m test test_asyncio". Remove the concept of "STDTESTS". Python is now mature enough to not have to bother with that anymore. Removing STDTESTS simplify the code.
1 parent 7a6cc3e commit 174e9da

File tree

2 files changed

+39
-44
lines changed

2 files changed

+39
-44
lines changed

Lib/test/libregrtest/main.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import unittest
1212
from test.libregrtest.cmdline import _parse_args
1313
from test.libregrtest.runtest import (
14-
findtests, runtest, get_abs_module, is_failed,
15-
STDTESTS, NOTTESTS, PROGRESS_MIN_TIME,
14+
findtests, split_test_packages, runtest, get_abs_module, is_failed,
15+
PROGRESS_MIN_TIME,
1616
Passed, Failed, EnvChanged, Skipped, ResourceDenied, Interrupted,
1717
ChildError, DidNotRun)
1818
from test.libregrtest.setup import setup_tests
@@ -246,26 +246,23 @@ def find_tests(self, tests):
246246
# add default PGO tests if no tests are specified
247247
setup_pgo_tests(self.ns)
248248

249-
stdtests = STDTESTS[:]
250-
nottests = NOTTESTS.copy()
249+
exclude = set()
251250
if self.ns.exclude:
252251
for arg in self.ns.args:
253-
if arg in stdtests:
254-
stdtests.remove(arg)
255-
nottests.add(arg)
252+
exclude.add(arg)
256253
self.ns.args = []
257254

258-
# if testdir is set, then we are not running the python tests suite, so
259-
# don't add default tests to be executed or skipped (pass empty values)
260-
if self.ns.testdir:
261-
alltests = findtests(self.ns.testdir, list(), set())
262-
else:
263-
alltests = findtests(self.ns.testdir, stdtests, nottests)
255+
alltests = findtests(testdir=self.ns.testdir, exclude=exclude)
264256

265257
if not self.ns.fromfile:
266-
self.selected = self.tests or self.ns.args or alltests
258+
self.selected = self.tests or self.ns.args
259+
if self.selected:
260+
self.selected = split_test_packages(self.selected)
261+
else:
262+
self.selected = alltests
267263
else:
268264
self.selected = self.tests
265+
269266
if self.ns.single:
270267
self.selected = self.selected[:1]
271268
try:

Lib/test/libregrtest/runtest.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,6 @@ def __str__(self) -> str:
125125
# the test is running in background
126126
PROGRESS_MIN_TIME = 30.0 # seconds
127127

128-
# small set of tests to determine if we have a basically functioning interpreter
129-
# (i.e. if any of these fail, then anything else is likely to follow)
130-
STDTESTS = [
131-
'test_grammar',
132-
'test_opcodes',
133-
'test_dict',
134-
'test_builtin',
135-
'test_exceptions',
136-
'test_types',
137-
'test_unittest',
138-
'test_doctest',
139-
'test_doctest2',
140-
'test_support'
141-
]
142-
143-
# set of tests that we don't want to be executed when using regrtest
144-
NOTTESTS = set()
145-
146128
#If these test directories are encountered recurse into them and treat each
147129
# test_ .py or dir as a separate test module. This can increase parallelism.
148130
# Beware this can't generally be done for any directory with sub-tests as the
@@ -166,22 +148,38 @@ def findtestdir(path=None):
166148
return path or os.path.dirname(os.path.dirname(__file__)) or os.curdir
167149

168150

169-
def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS, *, split_test_dirs=SPLITTESTDIRS, base_mod=""):
151+
def findtests(*, testdir=None, exclude=(),
152+
split_test_dirs=SPLITTESTDIRS, base_mod=""):
170153
"""Return a list of all applicable test modules."""
171154
testdir = findtestdir(testdir)
172-
names = os.listdir(testdir)
173155
tests = []
174-
others = set(stdtests) | nottests
175-
for name in names:
156+
for name in os.listdir(testdir):
176157
mod, ext = os.path.splitext(name)
177-
if mod[:5] == "test_" and mod not in others:
178-
if mod in split_test_dirs:
179-
subdir = os.path.join(testdir, mod)
180-
mod = f"{base_mod or 'test'}.{mod}"
181-
tests.extend(findtests(subdir, [], nottests, split_test_dirs=split_test_dirs, base_mod=mod))
182-
elif ext in (".py", ""):
183-
tests.append(f"{base_mod}.{mod}" if base_mod else mod)
184-
return stdtests + sorted(tests)
158+
if (not mod.startswith("test_")) or (mod in exclude):
159+
continue
160+
if mod in split_test_dirs:
161+
subdir = os.path.join(testdir, mod)
162+
mod = f"{base_mod or 'test'}.{mod}"
163+
tests.extend(findtests(testdir=subdir, exclude=exclude,
164+
split_test_dirs=split_test_dirs, base_mod=mod))
165+
elif ext in (".py", ""):
166+
tests.append(f"{base_mod}.{mod}" if base_mod else mod)
167+
return sorted(tests)
168+
169+
170+
def split_test_packages(tests, *, testdir=None, exclude=(),
171+
split_test_dirs=SPLITTESTDIRS):
172+
testdir = findtestdir(testdir)
173+
splitted = []
174+
for name in tests:
175+
if name in split_test_dirs:
176+
subdir = os.path.join(testdir, name)
177+
splitted.extend(findtests(testdir=subdir, exclude=exclude,
178+
split_test_dirs=split_test_dirs,
179+
base_mod=name))
180+
else:
181+
splitted.append(name)
182+
return splitted
185183

186184

187185
def get_abs_module(ns: Namespace, test_name: str) -> str:

0 commit comments

Comments
 (0)