def remove_local_modules_from_sys(testdir):
 for (modname, mod) in list(sys.modules.items()):
  if (mod is None):
   continue
  if (not hasattr(mod, '__file__')):
   continue
  modfile = mod.__file__
  if ((not osp.isabs(modfile)) or modfile.startswith(testdir)):
   del sys.modules[modname]

def remove_local_modules_from_sys ( testdir ) : for ( modname , mod ) in list ( sys . modules . items ( ) ) : if ( mod is None ) : continue if ( not hasattr ( mod , '__file__' ) ) : continue modfile = mod . __file__ if ( ( not osp . isabs ( modfile ) ) or modfile . startswith ( testdir ) ) : del sys . modules [ modname ]
remove all modules from cache that come from testdir this is used to avoid strange side-effects when using the testall() mode of pytest .