]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
tests: don't restore stopped mock that is set in setUp()
authorIhar Hrachyshka <ihrachys@redhat.com>
Wed, 14 Jan 2015 15:22:52 +0000 (16:22 +0100)
committerIhar Hrachyshka <ihrachys@redhat.com>
Wed, 14 Jan 2015 15:22:52 +0000 (16:22 +0100)
setUp() will be called for each new test case, so there is no need to
explicitly restore the mock.

Change-Id: I92d41706df19d028269f074937343dd18aa140a0

neutron/tests/unit/test_dhcp_agent.py

index 28b382b9aad7e80fd2a4076875a0475eee64cfcc..b18f3e67909a813d095b21590f33cae1f79423ca 100644 (file)
@@ -773,26 +773,22 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
         cfg.CONF.set_override('log_file', 'test.log')
         class_path = 'neutron.agent.linux.ip_lib.IPWrapper'
         self.external_process_p.stop()
-        # Ensure the mock is restored if this test fail
-        try:
-            with mock.patch(class_path) as ip_wrapper:
-                self.dhcp.enable_isolated_metadata_proxy(network)
-                ip_wrapper.assert_has_calls([mock.call(
-                    'sudo',
-                    'qdhcp-12345678-1234-5678-1234567890ab'),
-                    mock.call().netns.execute([
-                        'neutron-ns-metadata-proxy',
-                        mock.ANY,
-                        mock.ANY,
-                        '--router_id=forzanapoli',
-                        mock.ANY,
-                        mock.ANY,
-                        '--debug',
-                        ('--log-file=neutron-ns-metadata-proxy-%s.log' %
-                         network.id)], addl_env=None)
-                ])
-        finally:
-            self.external_process_p.start()
+        with mock.patch(class_path) as ip_wrapper:
+            self.dhcp.enable_isolated_metadata_proxy(network)
+            ip_wrapper.assert_has_calls([mock.call(
+                'sudo',
+                'qdhcp-12345678-1234-5678-1234567890ab'),
+                mock.call().netns.execute([
+                    'neutron-ns-metadata-proxy',
+                    mock.ANY,
+                    mock.ANY,
+                    '--router_id=forzanapoli',
+                    mock.ANY,
+                    mock.ANY,
+                    '--debug',
+                    ('--log-file=neutron-ns-metadata-proxy-%s.log' %
+                     network.id)], addl_env=None)
+            ])
 
     def test_enable_isolated_metadata_proxy_with_metadata_network(self):
         self._test_metadata_network(fake_meta_network)