summaryrefslogtreecommitdiff
path: root/HACKING.rst
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-03-03 17:53:41 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-03-04 17:22:36 +0000
commit8813ab185d0b6ad1c111e7f9e346e2ce91c8113b (patch)
tree13d4ae5f62ade4142c8b23ea1738742d90db6519 /HACKING.rst
parentd0cae6b5a16a5873afbcd47ba8ee5e97b6a25072 (diff)
downloadnova-8813ab185d0b6ad1c111e7f9e346e2ce91c8113b.tar.gz
assertRaises(Exception, ...) considered harmful
Expecting that Exception is raised can end up passing an a test when an unexpected error occurs. For instance, errors in the unit test itself can be masked: https://review.openstack.org/4848 https://review.openstack.org/4873 https://review.openstack.org/4874 Change a variety of unit tests to expect a more specific exception so we don't run into false positive tests in the future. Change-Id: Ibc0c63b1f6b5574a3ce93d9f02c9d1ff5ac4a8b0
Diffstat (limited to 'HACKING.rst')
-rw-r--r--HACKING.rst12
1 files changed, 12 insertions, 0 deletions
diff --git a/HACKING.rst b/HACKING.rst
index b7e2564d69..1945534329 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -181,6 +181,18 @@ 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
----------------