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/testing/README.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'nova/testing') diff --git a/nova/testing/README.rst b/nova/testing/README.rst index 036f1c77d..67fa33d1d 100644 --- a/nova/testing/README.rst +++ b/nova/testing/README.rst @@ -33,6 +33,17 @@ Using Fakes TBD +test.TestCase +------------- +The TestCase class from nova.test (generally imported as test) will +automatically manage self.stubs using the stubout module and self.mox +using the mox module during the setUp step. They will automatically +verify and clean up during the tearDown step. + +If using test.TestCase, calling the super class setUp is required and +calling the super class tearDown is required to be last if tearDown +is overriden. + Writing Functional Tests ------------------------ @@ -42,3 +53,14 @@ Writing Integration Tests ------------------------- TBD + +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) -- cgit