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