@contextmanager
def patch_pkgutil_get_loader(wrapper_class=LimitedLoaderMockWrapper):
 old_get_loader = pkgutil.get_loader
 def get_loader(*args, **kwargs):
  return wrapper_class(old_get_loader(*args, **kwargs))
 try:
  pkgutil.get_loader = get_loader
  (yield)
 finally:
  pkgutil.get_loader = old_get_loader

@ contextmanager def patch_pkgutil_get_loader ( wrapper_class = LimitedLoaderMockWrapper ) : old_get_loader = pkgutil . get_loader def get_loader ( * args , ** kwargs ) : return wrapper_class ( old_get_loader ( * args , ** kwargs ) ) try : pkgutil . get_loader = get_loader ( yield ) finally : pkgutil . get_loader = old_get_loader
patch pkgutil .