﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14774	assertNumQueries is buggy with views and the test client if used more than once in a test	Luke Plant	Jonas Obrist	"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`
"		closed	Testing framework	1.2		fixed	blocker	chris.peplin@…	Accepted	1	0	0	0	0	0
