title: Django: is there a way to count SQL queries from an unit test?
body: <p>I am trying to find out the number of queries executed by a utility function. I have written a unit test for this function and the function is working well. What I would like to do is track the number of SQL queries executed by the function so that I can see if there is any improvement after some refactoring.</p>
  
  <pre><code>def do_something_in_the_database():
      # Does something in the database
      # return result
  
  class DoSomethingTests(django.test.TestCase):
      def test_function_returns_correct_values(self):
          self.assertEqual(n, &lt;number of SQL queries executed&gt;)
  </code></pre>
  
  <p>EDIT: I found out that there is a pending Django <a href="http://code.djangoproject.com/ticket/5416" rel="noreferrer">feature request</a> for this. However the ticket is still open. In the meantime is there another way to go about this?</p>