assertNumQueries is buggy with views and the test client if used more than once in a test
|Reported by:||Luke Plant||Owned by:||Jonas Obrist|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
With code like this:
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.
- Using assertNumQueries either with the 'with' statement or passing a function in.
- with SQLite (haven't tested with others)
- with or without the
Change History (11)
comment:1 Changed 6 years ago by
|Patch needs improvement:||unset|
comment:2 Changed 6 years ago by
|Component:||Uncategorized → Testing framework|
|Triage Stage:||Unreviewed → Accepted|