code: def findtests(
      *,
      testdir: StrPath | None = None,
      exclude=(),
      split_test_dirs: set[TestName] = SPLITTESTDIRS,
      base_mod: str = "",
  ) -> TestList:
      """Return a list of all applicable test modules."""
      testdir = findtestdir(testdir)
      tests = []
      for name in os.listdir(testdir):
          mod, ext = os.path.splitext(name)
          if (not mod.startswith("test_")) or (mod in exclude):
              continue
          if base_mod:
              fullname = f"{base_mod}.{mod}"
          else:
              fullname = mod
          if fullname in split_test_dirs:
              subdir = os.path.join(testdir, mod)
              if not base_mod:
                  fullname = f"test.{mod}"
              tests.extend(
                  findtests(
                      testdir=subdir,
                      exclude=exclude,
                      split_test_dirs=split_test_dirs,
                      base_mod=fullname,
                  )
              )
          elif ext in (".py", ""):
              tests.append(fullname)
      return sorted(tests)
  
file_path: cpython/Lib/test/libregrtest/findtests.py
imports: import os
  import sys
  import unittest
  from test import support
  from .filter import match_test, set_match_tests
  from .utils import StrPath, TestName, TestTuple, TestList, TestFilter, abs_module_name, count, printlist
label_desc: Use image node_id 2 for calling a global function with example usage: findtests() and returns: sorted