#14774: assertNumQueries is buggy with views and the test client if used more 
than
once in a test
---------------------------+------------------------------------------------
 Reporter:  lukeplant      |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Uncategorized  |     Version:  1.2       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 With code like this:

 {{{
 #!python
 with self.assertNumQueries(5):
     self.client.get("some/view/")

 with self.assertNumQueries(5):
     self.client.get("some/view/")
 }}}

 The second one always fails, with '0' being the number of queries it
 calculates. (I do not have any caching enabled).

 If the second `client.get` goes to a view that actually uses less queries
 than the first, then assertNumQueries calculates a negative number of
 queries, which seems to be the true number minus the number of queries
 from the last assertNumQueries. I can't quite pin down the behaviour.

 I'm guessing this has to do with the way test client/request life-
 cycle/connections interact. I do not see this with normal queries done
 directly in the function.

 If someone else could confirm that would be helpful.

 This happens:
  * Using assertNumQueries either with the 'with' statement or passing a
 function in.
  * with SQLite (haven't tested with others)
  * with or without the `TransactionMiddleware`

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14774>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to