def get_tests_modules(basepath=this_dir_path, gui=True, packages=None):
 py_ext = '.py'
 for (dirpath, dirnames, filenames) in os.walk(basepath):
  for dirname in list(dirnames):
   if (dirname[0] == '.'):
    dirnames.remove(dirname)
  if (is_package(dirpath) and filenames):
   pkg_name = dirpath[(len(basepath) + len(os.sep)):].replace('/', '.')
   if (packages and (pkg_name not in packages)):
    continue
   filenames = filter((lambda x: (x.startswith('test_') and x.endswith(py_ext))), filenames)
   for name in filenames:
    try:
     (yield importlib.import_module(('.%s' % name[:(- len(py_ext))]), pkg_name))
    except test.test_support.ResourceDenied:
     if gui:
      raise

def get_tests_modules ( basepath = this_dir_path , gui = True , packages = None ) : py_ext = '.py' for ( dirpath , dirnames , filenames ) in os . walk ( basepath ) : for dirname in list ( dirnames ) : if ( dirname [ 0 ] == '.' ) : dirnames . remove ( dirname ) if ( is_package ( dirpath ) and filenames ) : pkg_name = dirpath [ ( len ( basepath ) + len ( os . sep ) ) : ] . replace ( '/' , '.' ) if ( packages and ( pkg_name not in packages ) ) : continue filenames = filter ( ( lambda x : ( x . startswith ( 'test_' ) and x . endswith ( py_ext ) ) ) , filenames ) for name in filenames : try : ( yield importlib . import_module ( ( '.%s' % name [ : ( - len ( py_ext ) ) ] ) , pkg_name ) ) except test . test_support . ResourceDenied : if gui : raise
this will import and yield modules whose names start with test_ and are inside packages found in the path starting at basepath .