From: Kevin Benton Date: Sun, 14 Sep 2014 09:22:57 +0000 (-0700) Subject: Fix a test_db_plugin unit test side_effect usage X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=463dee2a943d1dc39f78eb26637d1b252d72d080;p=openstack-build%2Fneutron-build.git 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 --- 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')