From 9bc8d887c76b987cc4c76c9a80760e1b315fc80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sun, 17 Mar 2013 11:26:27 +0200 Subject: [PATCH] Fixed memory leak in tests The AssertNumQueriesContext didn't reset connection's use_debug_cursor in case there was an exception. This resulted in leaking query strings into connection.queries. Maximum memory use pre-patch was around 700MB, post-patch it is around 200MB for Django's test suite. --- django/test/testcases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 83762ddee4..87779eabfd 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -162,9 +162,9 @@ class _AssertNumQueriesContext(CaptureQueriesContext): super(_AssertNumQueriesContext, self).__init__(connection) def __exit__(self, exc_type, exc_value, traceback): + super(_AssertNumQueriesContext, self).__exit__(exc_type, exc_value, traceback) if exc_type is not None: return - super(_AssertNumQueriesContext, self).__exit__(exc_type, exc_value, traceback) executed = len(self) self.test_case.assertEqual( executed, self.num, "%d queries executed, %d expected" % (