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
This commit is contained in:
12
HACKING.rst
12
HACKING.rst
@@ -181,18 +181,6 @@ For more information on creating unit tests and utilizing the testing
|
||||
infrastructure in OpenStack Nova, please read nova/testing/README.rst.
|
||||
|
||||
|
||||
Unit Tests and assertRaises
|
||||
---------------------------
|
||||
When asserting that a test should raise an exception, test against the
|
||||
most specific exception possible. An overly broad exception type (like
|
||||
Exception) can mask errors in the unit test itself.
|
||||
|
||||
Example::
|
||||
|
||||
self.assertRaises(exception.InstanceNotFound, db.instance_get_by_uuid,
|
||||
elevated, instance_uuid)
|
||||
|
||||
|
||||
openstack-common
|
||||
----------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user