@pytest.fixture(params=(True, False))
def limit_loader(request, monkeypatch):
 if (not request.param):
  return
 class LimitedLoader(object, ):
  def __init__(self, loader):
   self.loader = loader
  def __getattr__(self, name):
   if (name in ('archive', 'get_filename')):
    msg = ('Mocking a loader which does not have `%s.`' % name)
    raise AttributeError(msg)
   return getattr(self.loader, name)
 old_get_loader = pkgutil.get_loader
 def get_loader(*args, **kwargs):
  return LimitedLoader(old_get_loader(*args, **kwargs))
 monkeypatch.setattr(pkgutil, 'get_loader', get_loader)

@ pytest . fixture ( params = ( True , False ) ) def limit_loader ( request , monkeypatch ) : if ( not request . param ) : return class LimitedLoader ( object , ) : def __init__ ( self , loader ) : self . loader = loader def __getattr__ ( self , name ) : if ( name in ( 'archive' , 'get_filename' ) ) : msg = ( 'Mocking a loader which does not have `%s.`' % name ) raise AttributeError ( msg ) return getattr ( self . loader , name ) old_get_loader = pkgutil . get_loader def get_loader ( * args , ** kwargs ) : return LimitedLoader ( old_get_loader ( * args , ** kwargs ) ) monkeypatch . setattr ( pkgutil , 'get_loader' , get_loader )
patch pkgutil .