summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--HACKING.rst12
-rw-r--r--nova/test.py6
-rw-r--r--nova/testing/README.rst22
-rw-r--r--nova/tests/test_network.py8
4 files changed, 32 insertions, 16 deletions
diff --git a/HACKING.rst b/HACKING.rst
index 194553432..b7e2564d6 100644
--- a/HACKING.rst
+++ b/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
----------------
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():
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)
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index ba9dd6e12..7e7ae6b4b 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -135,8 +135,8 @@ class FlatNetworkTestCase(test.TestCase):
is_admin=False)
def tearDown(self):
- super(FlatNetworkTestCase, self).tearDown()
self.network.instance_dns_manager.delete_dns_file()
+ super(FlatNetworkTestCase, self).tearDown()
def test_get_instance_nw_info(self):
fake_get_instance_nw_info = fake_network.fake_get_instance_nw_info
@@ -1277,8 +1277,8 @@ class FloatingIPTestCase(test.TestCase):
is_admin=False)
def tearDown(self):
- super(FloatingIPTestCase, self).tearDown()
self.network.floating_dns_manager.delete_dns_file()
+ super(FloatingIPTestCase, self).tearDown()
def test_double_deallocation(self):
instance_ref = db.api.instance_create(self.context,
@@ -1480,8 +1480,8 @@ class InstanceDNSTestCase(test.TestCase):
is_admin=False)
def tearDown(self):
- super(InstanceDNSTestCase, self).tearDown()
self.network.instance_dns_manager.delete_dns_file()
+ super(InstanceDNSTestCase, self).tearDown()
def test_dns_domains_private(self):
zone1 = 'testzone'
@@ -1525,10 +1525,10 @@ class LdapDNSTestCase(test.TestCase):
self.driver.create_domain(domain2)
def tearDown(self):
- super(LdapDNSTestCase, self).tearDown()
self.driver.delete_domain(domain1)
self.driver.delete_domain(domain2)
sys.modules['ldap'] = self.saved_ldap
+ super(LdapDNSTestCase, self).tearDown()
def test_ldap_dns_domains(self):
domains = self.driver.get_domains()