]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Improve usage of MagicMocks in ML2 and L3 tests
authorKevin Benton <blak111@gmail.com>
Tue, 6 May 2014 04:19:08 +0000 (04:19 +0000)
committerKevin Benton <blak111@gmail.com>
Fri, 30 May 2014 04:21:29 +0000 (21:21 -0700)
Removes usage of a MagicMock in a case where it's not needed.
Replaces a manual function replacement with a mock.patch call
so it's correctly cleaned up by mock.patch.stopall.

Partial-Bug: #1316401
Change-Id: I8f2f7e9eca2aeaa3b65be1b451e96ed2146950f4

neutron/tests/unit/ml2/test_rpcapi.py
neutron/tests/unit/test_l3_plugin.py

index 0f4a858b72bbdb77f6bc1de28f118420420f4982..a2d3bf0eb5a17c04cbaeeee20db2407287fcd2a2 100644 (file)
@@ -38,11 +38,9 @@ class RpcApiTestCase(base.BaseTestCase):
         if rpc_method == 'cast' and method == 'run_instance':
             kwargs['call'] = False
 
-        rpc_method_mock = mock.Mock()
-        rpc_method_mock.return_value = expected_retval
-        setattr(rpc, rpc_method, rpc_method_mock)
-
-        retval = getattr(rpcapi, method)(ctxt, **kwargs)
+        with mock.patch.object(rpc, rpc_method) as rpc_method_mock:
+            rpc_method_mock.return_value = expected_retval
+            retval = getattr(rpcapi, method)(ctxt, **kwargs)
 
         self.assertEqual(retval, expected_retval)
 
index e4d28513cf1f27b0207fafbef951d0103b01585b..c138a7875c84b531692aca175531f2c53da6b59b 100644 (file)
@@ -1880,9 +1880,8 @@ class L3BaseForIntTests(test_db_plugin.NeutronDbPluginV2TestCase):
         ext_mgr = ext_mgr or L3TestExtensionManager()
 
         if self.mock_rescheduling:
-            rescheduling_patcher = mock.patch(
-                '%s._check_router_needs_rescheduling' % plugin)
-            rescheduling_patcher.start().return_value = False
+            mock.patch('%s._check_router_needs_rescheduling' % plugin,
+                       new=lambda *a: False).start()
 
         super(L3BaseForIntTests, self).setUp(plugin=plugin, ext_mgr=ext_mgr,
                                              service_plugins=service_plugins)