Query count decorator for TestCase

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def check_query_count(num_queries):
    def decorator(func):
        @wraps(func)
        def inner(self, *args, **kwargs):
            initial_queries = len(connection.queries)
            ret = func(self, *args, **kwargs)
            final_queries = len(connection.queries)
            if settings.DEBUG:
                self.assertEqual(final_queries - initial_queries, num_queries)
            return ret
        return inner
    return decorator

More like this

  1. Decorator and context manager to override settings by jezdez 1 year ago
  2. TestCase base class to easily temporarily change module values by SmileyChris 1 year, 10 months ago
  3. Automatic testing of add and changelist admin views by Taifu 9 months ago
  4. Testrunner with testmodels by nfg 2 years, 3 months ago
  5. Monkey-patch Django's test client to return WSGIRequest objects by robmadole 1 year, 6 months ago

Comments

(Forgotten your password?)