From fb7d1fb8253e55437858358793c9fb02fbff0ba0 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Tue, 6 Mar 2012 16:58:03 +0000 Subject: Clear created attributes when tearing down tests unittest will keep each test case around after completion pinning any objects references by attributes on the test case. This can bloat the memory used during a full test suite run to the point where the test suite will require much more memory than running all of the services does. On systems witout lots of memory, test suite failures will occur as test cases cannot fork to execute programs. Clearing out __dict__ of any attributes that don't start with a _ (since some are needed by unittest itself) reduces memory significantly. This does require the super class tearDown to be called last in some cases however. Change-Id: I0e660b6c2a77c5613c5a523ba0a64c3d7f6dd128 --- nova/test.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'nova/test.py') diff --git a/nova/test.py b/nova/test.py index b38de5303..87e1ce322 100644 --- a/nova/test.py +++ b/nova/test.py @@ -177,6 +177,12 @@ class TestCase(unittest.TestCase): except Exception: pass + # Delete attributes that don't start with _ so they don't pin + # memory around unnecessarily for the duration of the test + # suite + for key in [k for k in self.__dict__.keys() if k[0] != '_']: + del self.__dict__[key] + def flags(self, **kw): """Override flag variables for a test.""" for k, v in kw.iteritems(): -- cgit