From cd0802f604ecd773f0d0fa0ad5c8a0023231a4ee Mon Sep 17 00:00:00 2001 From: Henry Gessau Date: Wed, 19 Oct 2016 14:24:47 -0400 Subject: [PATCH] Enable fatal exceptions during tests This allows tests to catch string format errors in exception messages. Change-Id: I66d0363c02ef99482d4bec27b90584f8cea80e7a --- neutron_lib/tests/_base.py | 6 ++++++ neutron_lib/tests/unit/test_exceptions.py | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/neutron_lib/tests/_base.py b/neutron_lib/tests/_base.py index 85e1f49..7facdf0 100644 --- a/neutron_lib/tests/_base.py +++ b/neutron_lib/tests/_base.py @@ -29,6 +29,7 @@ import testtools from neutron_lib._i18n import _ from neutron_lib import constants +from neutron_lib import exceptions from neutron_lib.tests import _post_mortem_debug as post_mortem_debug from neutron_lib.tests import _tools as tools @@ -117,6 +118,11 @@ class BaseTestCase(testtools.TestCase): def setUp(self): super(BaseTestCase, self).setUp() + # Enabling 'use_fatal_exceptions' allows us to catch string + # substitution format errors in exception messages. + mock.patch.object(exceptions.NeutronException, 'use_fatal_exceptions', + return_value=True).start() + # Update the default QueuePool parameters. These can be tweaked by the # conf variables - max_pool_size, max_overflow and pool_timeout db_options.set_defaults( diff --git a/neutron_lib/tests/unit/test_exceptions.py b/neutron_lib/tests/unit/test_exceptions.py index 69c0ea0..fe2ac7b 100644 --- a/neutron_lib/tests/unit/test_exceptions.py +++ b/neutron_lib/tests/unit/test_exceptions.py @@ -36,7 +36,6 @@ class TestExceptions(base.BaseTestCase): raise_exc_class = functools.partial(_raise, exc_class) e = self.assertRaises(exc_class, raise_exc_class, **kwargs) self.assertEqual(expected_msg, str(e)) - self.assertFalse(e.use_fatal_exceptions()) def test_base(self): self._check_nexc( @@ -64,7 +63,7 @@ class TestExceptions(base.BaseTestCase): self._check_nexc( ne.BadRequest, _('Bad A request: B.'), - bad_resource='A', bad_msg='B') + resource='A', msg='B') except AttributeError: pass