title: How to test database connectivity in python?
body: <p>I am accessing a MySQL database from python via MySQLdb library. I am attempting to test the database connection as shown below. </p>
  
  <pre><code>db = MySQLdb.connect(self.server, self.user, 
                       self.passwd, self.schema)
  cursor = db.cursor()        
  try:
      cursor.execute("SELECT VERSION()")
      results = cursor.fetchone()
      ver = results[0]
      if (ver is None):
          return False
      else:
          return True               
  except:
      print "ERROR IN CONNECTION"
      return False
  </code></pre>
  
  <p>Is this the right way one should test the connectivity when writing unit testcases? If there is a better way, please enlighten!</p>