def test_meta_path_before_builtins():
 class MyException(Exception, ):
  pass
 class K:
  def find_module(self, name, path):
   if (name == 'time'):
    return self
   return None
  def load_module(self, name):
   raise MyException
 if ('time' in sys.modules):
  del sys.modules['time']
 loader = K()
 sys.meta_path.append(loader)
 try:
  import time
  AssertUnreachable()
 except MyException:
  pass
 sys.meta_path.remove(loader)
 import time

def test_meta_path_before_builtins ( ) : class MyException ( Exception , ) : pass class K : def find_module ( self , name , path ) : if ( name == 'time' ) : return self return None def load_module ( self , name ) : raise MyException if ( 'time' in sys . modules ) : del sys . modules [ 'time' ] loader = K ( ) sys . meta_path . append ( loader ) try : import time AssertUnreachable ( ) except MyException : pass sys . meta_path . remove ( loader ) import time
the meta path should be consulted before builtins are loaded .