diff --git a/neutron/tests/unit/cisco/test_nexus_plugin.py b/neutron/tests/unit/cisco/test_nexus_plugin.py index 58bf90f1f2f..ab41b22ea2c 100644 --- a/neutron/tests/unit/cisco/test_nexus_plugin.py +++ b/neutron/tests/unit/cisco/test_nexus_plugin.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import contextlib import mock from oslo.config import cfg @@ -148,12 +149,12 @@ class TestCiscoNexusPlugin(base.BaseTestCase): self.addCleanup(db.clear_db) # Use a mock netconf client self.mock_ncclient = mock.Mock() - self.patch_obj = mock.patch.dict('sys.modules', - {'ncclient': self.mock_ncclient}) - self.patch_obj.start() - with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin, - '__init__', new=new_nexus_init): + with contextlib.nested( + mock.patch.dict('sys.modules', {'ncclient': self.mock_ncclient}), + mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin, + '__init__', new=new_nexus_init) + ): self._cisco_nexus_plugin = cisco_nexus_plugin_v2.NexusPlugin() # Set the Cisco config module's first configured device IP address diff --git a/neutron/tests/unit/test_linux_interface.py b/neutron/tests/unit/test_linux_interface.py index 9d278ea5109..0ecf2de0d12 100644 --- a/neutron/tests/unit/test_linux_interface.py +++ b/neutron/tests/unit/test_linux_interface.py @@ -515,8 +515,6 @@ class TestMidonetInterfaceDriver(TestBase): self.conf = config.setup_conf() self.conf.register_opts(interface.OPTS) config.register_root_helper(self.conf) - self.device_exists_p = mock.patch.object(ip_lib, 'device_exists') - self.device_exists = self.device_exists_p.start() self.driver = interface.MidonetInterfaceDriver(self.conf) self.network_id = uuidutils.generate_uuid() self.port_id = uuidutils.generate_uuid()