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 5416 Add assertNumQueries() to testing framework Adrian Holovaty Alex Gaynor "The Django testing framework should provide {{{assertNumQueries()}}}, which would assert that a given action executed a given number of database queries. This should work at the view level (""view X uses 3 queries total"") or the individual statement level (""model method X uses only 1 query""). This might have to be implemented as two methods -- a ""start counting"" method and a ""stop counting"" method: {{{ #!python def test_something(self): self.startCountingQueries() do_something_that_should_only_use_two_queries() self.assertNumQueries(2) }}} In this example, {{{startCountingQueries()}}} would reset the counter to 0, and every query would be tallied from that point on. {{{assertNumQueries()}}} would simply assert the query count was the given number. Note that this depends on #5415, which provides signals for every SQL query." closed Testing framework dev fixed feature_request egmanoj@… Alexander Koshelev Mikhail Korobov Accepted 1 0 0 1 0 0