summaryrefslogtreecommitdiffstats
path: root/nova/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'nova/test.py')
-rw-r--r--nova/test.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/nova/test.py b/nova/test.py
index dcde09b86..a2edeb51a 100644
--- a/nova/test.py
+++ b/nova/test.py
@@ -291,3 +291,30 @@ class TestCase(unittest.TestCase):
self.assertFalse(a in b, *args, **kwargs)
else:
f(a, b, *args, **kwargs)
+
+ def assertNotRaises(self, exc_class, func, *args, **kwargs):
+ """Assert that a particular exception is not raised.
+
+ If exc_class is None, then we assert that *no* error is raised.
+
+ Otherwise, we assert that only a particular error wasn't raised;
+ if any different exceptions were raised, we just silently capture
+ them and return.
+ """
+ exc_msg = kwargs.pop('exc_msg', '')
+
+ if exc_class is None:
+ # Ensure no errors were raised
+ try:
+ return func(*args, **kwargs)
+ except Exception:
+ raise
+ raise AssertionError(exc_msg)
+ else:
+ # Ensure a specific error wasn't raised
+ try:
+ return func(*args, **kwargs)
+ except exc_class:
+ raise AssertionError(exc_msg)
+ except Exception:
+ pass # Any other errors are fine