Remove TestCase.assertNotRaises

assertNotRaises appears to have been added to provide an easier way to
assert that an exception should not be raised by a particular call in
the test.

However, the implementation has a couple of problems.

The first is that it catches every other exception than the one specified,
and silently ignores them. This had lead to one bug where a legitimate bug
in the test (test_exception_with_rescheduling_enabled) was silently
ignored. The call intended to be tested was called with too few
arguments and the resulting TypeError was silently ignored.

The second is that assertNotRaises could be called with None, which
meant that no exceptions should be raised. However, this didn't do
anything other than reraise the original exception. Calling
assertNotRaises just adds an extra call with no value.

From a design stand point, it's not clear what value this assertion
provides since the test runner will already fail a test if an exception
is raised.

Change-Id: I64502dfa0e873f2bbd9b733a5fb63023e1b4e296
This commit is contained in:
Johannes Erdfelt
2012-10-01 16:38:50 +00:00
parent f8c5615654
commit 876ccd0340
3 changed files with 8 additions and 15 deletions

View File

@@ -1182,8 +1182,7 @@ class SMVolumeDBApiTestCase(test.TestCase):
def test_sm_backend_conf_delete_nonexisting(self):
ctxt = context.get_admin_context()
self.assertNotRaises(None, db.sm_backend_conf_delete,
ctxt, "FA15E-1D")
db.sm_backend_conf_delete(ctxt, "FA15E-1D")
def test_sm_flavor_create(self):
ctxt = context.get_admin_context()
@@ -1231,8 +1230,7 @@ class SMVolumeDBApiTestCase(test.TestCase):
def test_sm_flavor_delete_nonexisting(self):
ctxt = context.get_admin_context()
self.assertNotRaises(None, db.sm_flavor_delete,
ctxt, 7)
db.sm_flavor_delete(ctxt, 7)
def test_sm_flavor_get(self):
ctxt = context.get_admin_context()

View File

@@ -2437,9 +2437,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBase):
'destination_sr_ref': None,
'migrate_send_data': None
}}
self.assertNotRaises(None,
self.conn.check_can_live_migrate_source,
self.context,
self.conn.check_can_live_migrate_source(self.context,
{'host': 'host'},
dest_check_data)

View File

@@ -89,11 +89,8 @@ class XenSMTestCase(stubs.XenAPITestBase):
ctxt = context.get_admin_context()
beconf = self._setup_step(ctxt)
volume = self._create_volume()
self.assertNotRaises(None, self.driver.create_volume, volume)
self.assertNotRaises(None,
db.sm_volume_get,
ctxt,
volume['id'])
self.driver.create_volume(volume)
db.sm_volume_get(ctxt, volume['id'])
def test_local_path(self):
ctxt = context.get_admin_context()
@@ -106,7 +103,7 @@ class XenSMTestCase(stubs.XenAPITestBase):
beconf = self._setup_step(ctxt)
volume = self._create_volume()
self.driver.create_volume(volume)
self.assertNotRaises(None, self.driver.delete_volume, volume)
self.driver.delete_volume(volume)
self.assertRaises(exception.NotFound,
db.sm_volume_get,
ctxt,