diff options
author | Ben Nemec <bnemec@us.ibm.com> | 2013-07-02 10:59:02 -0500 |
---|---|---|
committer | Ben Nemec <bnemec@us.ibm.com> | 2013-07-02 10:59:02 -0500 |
commit | 323e465718174299f392e1fb12726593712a2d34 (patch) | |
tree | 5a42684642718bee1b78b9cdd5e3da8216f9a483 /tests | |
parent | 78649a52d90a63117f3213107b826cc561cef419 (diff) | |
download | oslo-323e465718174299f392e1fb12726593712a2d34.tar.gz oslo-323e465718174299f392e1fb12726593712a2d34.tar.xz oslo-323e465718174299f392e1fb12726593712a2d34.zip |
Add conditional exception reraise
In some cases we need to save an exception and reraise it only
under certain conditions. As written, the
save_and_reraise_exception context always reraises, which means
it can't always be used. This change adds a flag that allows
conditional reraising to address the limitation.
Change-Id: Ib5c6406a1b91daff94cc4aa305dcb7d6262aecdc
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_excutils.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/unit/test_excutils.py b/tests/unit/test_excutils.py index b8f9b96..1386eaa 100644 --- a/tests/unit/test_excutils.py +++ b/tests/unit/test_excutils.py @@ -52,6 +52,14 @@ class SaveAndReraiseTest(utils.BaseTestCase): self.assertEqual(str(e), msg) + def test_save_and_reraise_exception_no_reraise(self): + """Test that suppressing the reraise works.""" + try: + raise Exception('foo') + except Exception: + with excutils.save_and_reraise_exception() as ctxt: + ctxt.reraise = False + class ForeverRetryUncaughtExceptionsTest(utils.BaseTestCase): |