title: Python Unit Test : How to unit test the module which contains database operations?
body: <p>I am using pymysql client library to connect to the real database. I have a  function in module, where I connect to the database using pymysql and do only database insert operations.How to unit test this function in python without hitting the real database?</p>
  
  <pre><code>import pymysql
  
  def connectDB(self):
  
  # Connect to the database
  connection = pymysql.connect(host='localhost',
                               user='user',
                               password='passwd',
                               db='db')
  
  try:
      with connection.cursor() as cursor:
          # Create a new record
          sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
          cursor.execute(sql, ('newuser@some.com', 'newpassword'))
  
  
      connection.commit()
  </code></pre>
  
  <p>My python version is 2.7.</p>