code: def testmods_from_testdir(testdir):
      """Generate test modules in the given test dir.
  
      Modules are imported with 'testdir' first on sys.path.
      """
      testdir = normpath(testdir)
      for testmod_path in testmod_paths_from_testdir(testdir):
          testmod_name = splitext(basename(testmod_path))[0]
          log.debug("import test module '%s'", testmod_path)
          try:
              testabsdir = abspath(testdir)
              sys.path.insert(0, testabsdir)
              old_dir = os.getcwd()
              os.chdir(testdir)
              try:
                  testmod = importlib.import_module(testmod_name)
              finally:
                  os.chdir(old_dir)
                  sys.path.remove(testabsdir)
          except TestSkipped:
              _, ex, _ = sys.exc_info()
              log.warning("'%s' module skipped: %s", testmod_name, ex)
          except Exception:
              _, ex, _ = sys.exc_info()
              log.warning(
                  "could not import test module '%s': %s (skipping, "
                  "run with '-d' for full traceback)",
                  testmod_path,
                  ex,
              )
              if log.isEnabledFor(logging.DEBUG):
                  traceback.print_exc()
          else:
              yield testmod
  
imports: import os
  from os.path import join, basename, abspath, splitext, isfile, isdir, normpath, exists
  import sys
  import getopt
  import glob
  import time
  import unittest
  import importlib
  import logging
  import textwrap
  import traceback
label_desc: Use image node_id 4 for calling a global function with example usage: testmods_from_testdir(testdir) without return types