def testmods_from_testdir(testdir):
 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:
   iinfo = imp.find_module(testmod_name, [dirname(testmod_path)])
   testabsdir = abspath(testdir)
   sys.path.insert(0, testabsdir)
   old_dir = os.getcwd()
   os.chdir(testdir)
   try:
    testmod = imp.load_module(testmod_name, *iinfo)
   finally:
    os.chdir(old_dir)
    sys.path.remove(testabsdir)
  except TestSkipped:
   (_, ex, _) = sys.exc_info()
   log.warn("'%s' module skipped: %s", testmod_name, ex)
  except Exception:
   (_, ex, _) = sys.exc_info()
   log.warn("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)

def testmods_from_testdir ( testdir ) : 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 : iinfo = imp . find_module ( testmod_name , [ dirname ( testmod_path ) ] ) testabsdir = abspath ( testdir ) sys . path . insert ( 0 , testabsdir ) old_dir = os . getcwd ( ) os . chdir ( testdir ) try : testmod = imp . load_module ( testmod_name , * iinfo ) finally : os . chdir ( old_dir ) sys . path . remove ( testabsdir ) except TestSkipped : ( _ , ex , _ ) = sys . exc_info ( ) log . warn ( "'%s' module skipped: %s" , testmod_name , ex ) except Exception : ( _ , ex , _ ) = sys . exc_info ( ) log . warn ( "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 )
generate test modules in the given test dir .