mirror of https://github.com/python/cpython
gh-108388: regrtest splits test_asyncio package (#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.
This commit is contained in:
parent
7a6cc3eb66
commit
174e9da083
|
@ -11,8 +11,8 @@ import time
|
||||||
import unittest
|
import unittest
|
||||||
from test.libregrtest.cmdline import _parse_args
|
from test.libregrtest.cmdline import _parse_args
|
||||||
from test.libregrtest.runtest import (
|
from test.libregrtest.runtest import (
|
||||||
findtests, runtest, get_abs_module, is_failed,
|
findtests, split_test_packages, runtest, get_abs_module, is_failed,
|
||||||
STDTESTS, NOTTESTS, PROGRESS_MIN_TIME,
|
PROGRESS_MIN_TIME,
|
||||||
Passed, Failed, EnvChanged, Skipped, ResourceDenied, Interrupted,
|
Passed, Failed, EnvChanged, Skipped, ResourceDenied, Interrupted,
|
||||||
ChildError, DidNotRun)
|
ChildError, DidNotRun)
|
||||||
from test.libregrtest.setup import setup_tests
|
from test.libregrtest.setup import setup_tests
|
||||||
|
@ -246,26 +246,23 @@ class Regrtest:
|
||||||
# add default PGO tests if no tests are specified
|
# add default PGO tests if no tests are specified
|
||||||
setup_pgo_tests(self.ns)
|
setup_pgo_tests(self.ns)
|
||||||
|
|
||||||
stdtests = STDTESTS[:]
|
exclude = set()
|
||||||
nottests = NOTTESTS.copy()
|
|
||||||
if self.ns.exclude:
|
if self.ns.exclude:
|
||||||
for arg in self.ns.args:
|
for arg in self.ns.args:
|
||||||
if arg in stdtests:
|
exclude.add(arg)
|
||||||
stdtests.remove(arg)
|
|
||||||
nottests.add(arg)
|
|
||||||
self.ns.args = []
|
self.ns.args = []
|
||||||
|
|
||||||
# if testdir is set, then we are not running the python tests suite, so
|
alltests = findtests(testdir=self.ns.testdir, exclude=exclude)
|
||||||
# don't add default tests to be executed or skipped (pass empty values)
|
|
||||||
if self.ns.testdir:
|
|
||||||
alltests = findtests(self.ns.testdir, list(), set())
|
|
||||||
else:
|
|
||||||
alltests = findtests(self.ns.testdir, stdtests, nottests)
|
|
||||||
|
|
||||||
if not self.ns.fromfile:
|
if not self.ns.fromfile:
|
||||||
self.selected = self.tests or self.ns.args or alltests
|
self.selected = self.tests or self.ns.args
|
||||||
|
if self.selected:
|
||||||
|
self.selected = split_test_packages(self.selected)
|
||||||
|
else:
|
||||||
|
self.selected = alltests
|
||||||
else:
|
else:
|
||||||
self.selected = self.tests
|
self.selected = self.tests
|
||||||
|
|
||||||
if self.ns.single:
|
if self.ns.single:
|
||||||
self.selected = self.selected[:1]
|
self.selected = self.selected[:1]
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -125,24 +125,6 @@ class Timeout(Failed):
|
||||||
# the test is running in background
|
# the test is running in background
|
||||||
PROGRESS_MIN_TIME = 30.0 # seconds
|
PROGRESS_MIN_TIME = 30.0 # seconds
|
||||||
|
|
||||||
# small set of tests to determine if we have a basically functioning interpreter
|
|
||||||
# (i.e. if any of these fail, then anything else is likely to follow)
|
|
||||||
STDTESTS = [
|
|
||||||
'test_grammar',
|
|
||||||
'test_opcodes',
|
|
||||||
'test_dict',
|
|
||||||
'test_builtin',
|
|
||||||
'test_exceptions',
|
|
||||||
'test_types',
|
|
||||||
'test_unittest',
|
|
||||||
'test_doctest',
|
|
||||||
'test_doctest2',
|
|
||||||
'test_support'
|
|
||||||
]
|
|
||||||
|
|
||||||
# set of tests that we don't want to be executed when using regrtest
|
|
||||||
NOTTESTS = set()
|
|
||||||
|
|
||||||
#If these test directories are encountered recurse into them and treat each
|
#If these test directories are encountered recurse into them and treat each
|
||||||
# test_ .py or dir as a separate test module. This can increase parallelism.
|
# test_ .py or dir as a separate test module. This can increase parallelism.
|
||||||
# Beware this can't generally be done for any directory with sub-tests as the
|
# Beware this can't generally be done for any directory with sub-tests as the
|
||||||
|
@ -166,22 +148,38 @@ def findtestdir(path=None):
|
||||||
return path or os.path.dirname(os.path.dirname(__file__)) or os.curdir
|
return path or os.path.dirname(os.path.dirname(__file__)) or os.curdir
|
||||||
|
|
||||||
|
|
||||||
def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS, *, split_test_dirs=SPLITTESTDIRS, base_mod=""):
|
def findtests(*, testdir=None, exclude=(),
|
||||||
|
split_test_dirs=SPLITTESTDIRS, base_mod=""):
|
||||||
"""Return a list of all applicable test modules."""
|
"""Return a list of all applicable test modules."""
|
||||||
testdir = findtestdir(testdir)
|
testdir = findtestdir(testdir)
|
||||||
names = os.listdir(testdir)
|
|
||||||
tests = []
|
tests = []
|
||||||
others = set(stdtests) | nottests
|
for name in os.listdir(testdir):
|
||||||
for name in names:
|
|
||||||
mod, ext = os.path.splitext(name)
|
mod, ext = os.path.splitext(name)
|
||||||
if mod[:5] == "test_" and mod not in others:
|
if (not mod.startswith("test_")) or (mod in exclude):
|
||||||
if mod in split_test_dirs:
|
continue
|
||||||
subdir = os.path.join(testdir, mod)
|
if mod in split_test_dirs:
|
||||||
mod = f"{base_mod or 'test'}.{mod}"
|
subdir = os.path.join(testdir, mod)
|
||||||
tests.extend(findtests(subdir, [], nottests, split_test_dirs=split_test_dirs, base_mod=mod))
|
mod = f"{base_mod or 'test'}.{mod}"
|
||||||
elif ext in (".py", ""):
|
tests.extend(findtests(testdir=subdir, exclude=exclude,
|
||||||
tests.append(f"{base_mod}.{mod}" if base_mod else mod)
|
split_test_dirs=split_test_dirs, base_mod=mod))
|
||||||
return stdtests + sorted(tests)
|
elif ext in (".py", ""):
|
||||||
|
tests.append(f"{base_mod}.{mod}" if base_mod else mod)
|
||||||
|
return sorted(tests)
|
||||||
|
|
||||||
|
|
||||||
|
def split_test_packages(tests, *, testdir=None, exclude=(),
|
||||||
|
split_test_dirs=SPLITTESTDIRS):
|
||||||
|
testdir = findtestdir(testdir)
|
||||||
|
splitted = []
|
||||||
|
for name in tests:
|
||||||
|
if name in split_test_dirs:
|
||||||
|
subdir = os.path.join(testdir, name)
|
||||||
|
splitted.extend(findtests(testdir=subdir, exclude=exclude,
|
||||||
|
split_test_dirs=split_test_dirs,
|
||||||
|
base_mod=name))
|
||||||
|
else:
|
||||||
|
splitted.append(name)
|
||||||
|
return splitted
|
||||||
|
|
||||||
|
|
||||||
def get_abs_module(ns: Namespace, test_name: str) -> str:
|
def get_abs_module(ns: Namespace, test_name: str) -> str:
|
||||||
|
|
Loading…
Reference in New Issue