def skip_if_unavailable(modulename):
 def cantimport():
  try:
   __import__(modulename)
  except ImportError:
   return True
  else:
   return False
 return skip_if(cantimport)

def skip_if_unavailable ( modulename ) : def cantimport ( ) : try : __import__ ( modulename ) except ImportError : return True else : return False return skip_if ( cantimport )
a nose test decorator that only runs the decorated test if a module can be imported:: @skip_if_unavailable def test_mp(): raises skiptest if the module cannot be imported .