Skip to content

Commit

Permalink
pythongh-108388: regrtest splits test_asyncio package
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
vstinner committed Aug 24, 2023
1 parent 7a6cc3e commit 34ee8c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 8 additions & 4 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import unittest
from test.libregrtest.cmdline import _parse_args
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,
Passed, Failed, EnvChanged, Skipped, ResourceDenied, Interrupted,
ChildError, DidNotRun)
Expand Down Expand Up @@ -258,12 +258,16 @@ def find_tests(self, tests):
# if testdir is set, then we are not running the python tests suite, so
# don't add default tests to be executed or skipped (pass empty values)
if self.ns.testdir:
alltests = findtests(self.ns.testdir, list(), set())
alltests = findtests(self.ns.testdir, stdtests=list(), nottests=set())
else:
alltests = findtests(self.ns.testdir, stdtests, nottests)
alltests = findtests(self.ns.testdir, stdtests=stdtests, nottests=nottests)

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:
self.selected = self.tests
if self.ns.single:
Expand Down
20 changes: 18 additions & 2 deletions Lib/test/libregrtest/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def findtestdir(path=None):
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, *,
stdtests=STDTESTS, nottests=NOTTESTS,
split_test_dirs=SPLITTESTDIRS, base_mod=""):
"""Return a list of all applicable test modules."""
testdir = findtestdir(testdir)
names = os.listdir(testdir)
Expand All @@ -178,12 +180,26 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS, *, split_test_
if mod in split_test_dirs:
subdir = os.path.join(testdir, mod)
mod = f"{base_mod or 'test'}.{mod}"
tests.extend(findtests(subdir, [], nottests, split_test_dirs=split_test_dirs, base_mod=mod))
tests.extend(findtests(subdir, stdtests=[], nottests=nottests,
split_test_dirs=split_test_dirs, base_mod=mod))
elif ext in (".py", ""):
tests.append(f"{base_mod}.{mod}" if base_mod else mod)
return stdtests + sorted(tests)


def split_test_packages(tests, *, testdir=None, nottests=NOTTESTS, 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(subdir, stdtests=[], nottests=nottests,
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:
if test_name.startswith('test.') or ns.testdir:
return test_name
Expand Down

0 comments on commit 34ee8c7

Please sign in to comment.