From 323e465718174299f392e1fb12726593712a2d34 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 2 Jul 2013 10:59:02 -0500 Subject: 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 --- tests/unit/test_excutils.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') 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): -- cgit