From 463dee2a943d1dc39f78eb26637d1b252d72d080 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Sun, 14 Sep 2014 02:22:57 -0700 Subject: [PATCH] Fix a test_db_plugin unit test side_effect usage One of the unit tests didn't correctly use the side_effect parameter for a mock to return different responses to multiple calls, which resulted in an extra try-except block and an inline note. This commit fixes the side_effect and removes the extra catching code. Change-Id: Ifa1a6a15025b710ecbba956b5b848e32314cf0cf --- neutron/tests/unit/test_db_plugin.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index 0fb402311..0948cecb3 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -3901,16 +3901,9 @@ class TestNeutronDbPluginV2(base.BaseTestCase): '_rebuild_availability_ranges') as rebuild: exception = n_exc.IpAddressGenerationFailure(net_id='n') - generate.side_effect = exception - - # I want the side_effect to throw an exception once but I - # didn't see a way to do this. So, let it throw twice and - # catch the second one. Check below to ensure that - # _try_generate_ip was called twice. - try: - db_base_plugin_v2.NeutronDbPluginV2._generate_ip('c', 's') - except n_exc.IpAddressGenerationFailure: - pass + # fail first call but not second + generate.side_effect = [exception, None] + db_base_plugin_v2.NeutronDbPluginV2._generate_ip('c', 's') self.assertEqual(2, generate.call_count) rebuild.assert_called_once_with('c', 's') -- 2.45.2