assertTrue(mock.called) -> mock.assert_called 11/53111/1
authorEmma Foley <emma.l.foley@intel.com>
Mon, 5 Mar 2018 17:41:33 +0000 (17:41 +0000)
committerEmma Foley <emma.l.foley@intel.com>
Mon, 5 Mar 2018 17:41:33 +0000 (17:41 +0000)
When checking whether a mocked method has been called,
mock.assert_called or mock.assert_called_once should be
used, and not unittest.assertTrue(mock.called)

This change does this update.
It can be verified with:
  grep -irn "self.assertTrue(.*called)" --exclude-dir=.tox
And the replacement was done with:
  sed -i 's/self.assertTrue(\(.*\).called)/\1.assert_called_once()/g' <list_of_files>

Change-Id: I4f26e0c736bf33e0b2413c8e8c33dbdb91f090e2
JIRA: YARDSTICK-865
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
33 files changed:
yardstick/tests/unit/benchmark/contexts/test_heat.py
yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
yardstick/tests/unit/benchmark/contexts/test_node.py
yardstick/tests/unit/benchmark/core/test_task.py
yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py
yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py
yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py
yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py
yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py
yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py
yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py
yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py
yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py
yardstick/tests/unit/test_cmd/commands/test_env.py
yardstick/tests/unit/test_cmd/commands/test_testcase.py

index f48d6f3..479db8a 100644 (file)
@@ -365,7 +365,7 @@ class HeatContextTestCase(unittest.TestCase):
         self.test_context.key_filename = 'foo/bar/foobar'
         self.test_context.undeploy()
         mock_delete_key.assert_called()
-        self.assertTrue(mock_template.delete.called)
+        mock_template.delete.assert_called_once()
 
     @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
     def test_undeploy_no_teardown(self, mock_template):
index 22153e4..4dd9d40 100644 (file)
@@ -58,10 +58,10 @@ class KubernetesTestCase(unittest.TestCase):
                       mock_delete_services):
 
         self.k8s_context.undeploy()
-        self.assertTrue(mock_delete_ssh.called)
-        self.assertTrue(mock_delete_rcs.called)
-        self.assertTrue(mock_delete_pods.called)
-        self.assertTrue(mock_delete_services.called)
+        mock_delete_ssh.assert_called_once()
+        mock_delete_rcs.assert_called_once()
+        mock_delete_pods.assert_called_once()
+        mock_delete_services.assert_called_once()
 
     @mock.patch.object(kubernetes.KubernetesContext, '_create_services')
     @mock.patch.object(kubernetes.KubernetesContext, '_wait_until_running')
@@ -77,11 +77,11 @@ class KubernetesTestCase(unittest.TestCase):
 
         with mock.patch("yardstick.benchmark.contexts.kubernetes.time"):
             self.k8s_context.deploy()
-        self.assertTrue(mock_set_ssh_key.called)
-        self.assertTrue(mock_create_rcs.called)
-        self.assertTrue(mock_create_services.called)
-        self.assertTrue(mock_get_rc_pods.called)
-        self.assertTrue(mock_wait_until_running.called)
+        mock_set_ssh_key.assert_called_once()
+        mock_create_rcs.assert_called_once()
+        mock_create_services.assert_called_once()
+        mock_get_rc_pods.assert_called_once()
+        mock_wait_until_running.assert_called_once()
 
     @mock.patch.object(kubernetes, 'paramiko', **{"resource_filename.return_value": ""})
     @mock.patch.object(kubernetes, 'pkg_resources', **{"resource_filename.return_value": ""})
@@ -93,8 +93,8 @@ class KubernetesTestCase(unittest.TestCase):
         self.k8s_context._set_ssh_key()
         self.k8s_context._delete_ssh_key()
 
-        self.assertTrue(mock_create.called)
-        self.assertTrue(mock_delete.called)
+        mock_create.assert_called_once()
+        mock_delete.assert_called_once()
 
     @mock.patch.object(kubernetes.k8s_utils, 'read_pod_status')
     def test_wait_until_running(self, mock_read_pod_status):
@@ -136,34 +136,34 @@ class KubernetesTestCase(unittest.TestCase):
     @mock.patch.object(kubernetes.KubernetesContext, '_create_rc')
     def test_create_rcs(self, mock_create_rc):
         self.k8s_context._create_rcs()
-        self.assertTrue(mock_create_rc.called)
+        mock_create_rc.assert_called()
 
     @mock.patch.object(kubernetes.k8s_utils, 'create_replication_controller')
     def test_create_rc(self, mock_create_replication_controller):
         self.k8s_context._create_rc({})
-        self.assertTrue(mock_create_replication_controller.called)
+        mock_create_replication_controller.assert_called_once()
 
     @mock.patch.object(kubernetes.KubernetesContext, '_delete_rc')
     def test_delete_rcs(self, mock_delete_rc):
         self.k8s_context._delete_rcs()
-        self.assertTrue(mock_delete_rc.called)
+        mock_delete_rc.assert_called()
 
     @mock.patch.object(kubernetes.k8s_utils, 'delete_replication_controller')
     def test_delete_rc(self, mock_delete_replication_controller):
         self.k8s_context._delete_rc({})
-        self.assertTrue(mock_delete_replication_controller.called)
+        mock_delete_replication_controller.assert_called_once()
 
     @mock.patch.object(kubernetes.k8s_utils, 'get_node_list')
     def test_get_node_ip(self, mock_get_node_list):
         self.k8s_context._get_node_ip()
-        self.assertTrue(mock_get_node_list.called)
+        mock_get_node_list.assert_called_once()
 
     @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.create')
     def test_create_services(self, mock_create):
         self.k8s_context._create_services()
-        self.assertTrue(mock_create.called)
+        mock_create.assert_called()
 
     @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.delete')
     def test_delete_services(self, mock_delete):
         self.k8s_context._delete_services()
-        self.assertTrue(mock_delete.called)
+        mock_delete.assert_called()
index 9761f6d..8b23248 100644 (file)
@@ -176,7 +176,7 @@ class NodeContextTestCase(unittest.TestCase):
             'type': 'script'
         }
         obj.deploy()
-        self.assertTrue(dispatch_script_mock.called)
+        dispatch_script_mock.assert_called_once()
 
     @mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX))
     def test_deploy_anisible(self, dispatch_ansible_mock):
@@ -186,7 +186,7 @@ class NodeContextTestCase(unittest.TestCase):
             'type': 'ansible'
         }
         obj.deploy()
-        self.assertTrue(dispatch_ansible_mock.called)
+        dispatch_ansible_mock.assert_called_once()
 
     @mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX))
     def test_undeploy(self, dispatch_script_mock):
@@ -195,7 +195,7 @@ class NodeContextTestCase(unittest.TestCase):
             'type': 'script'
         }
         obj.undeploy()
-        self.assertTrue(dispatch_script_mock.called)
+        dispatch_script_mock.assert_called_once()
 
     @mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX))
     def test_undeploy_anisble(self, dispatch_ansible_mock):
@@ -204,7 +204,7 @@ class NodeContextTestCase(unittest.TestCase):
             'type': 'ansible'
         }
         obj.undeploy()
-        self.assertTrue(dispatch_ansible_mock.called)
+        dispatch_ansible_mock.assert_called_once()
 
     @mock.patch('{}.ssh.SSH._put_file_shell'.format(PREFIX))
     @mock.patch('{}.ssh.SSH.execute'.format(PREFIX))
@@ -224,8 +224,8 @@ class NodeContextTestCase(unittest.TestCase):
         execute_mock.return_value = (0, '', '')
         obj._execute_remote_script('node5', info)
 
-        self.assertTrue(put_file_mock.called)
-        self.assertTrue(execute_mock.called)
+        put_file_mock.assert_called_once()
+        execute_mock.assert_called()
 
     @mock.patch('{}.NodeContext._execute_local_script'.format(PREFIX))
     def test_execute_script_local(self, local_execute_mock):
@@ -234,7 +234,7 @@ class NodeContextTestCase(unittest.TestCase):
         obj = node.NodeContext()
         self.addCleanup(obj._delete_context)
         obj._execute_script(node_name, info)
-        self.assertTrue(local_execute_mock.called)
+        local_execute_mock.assert_called_once()
 
     @mock.patch('{}.NodeContext._execute_remote_script'.format(PREFIX))
     def test_execute_script_remote(self, remote_execute_mock):
@@ -243,7 +243,7 @@ class NodeContextTestCase(unittest.TestCase):
         obj = node.NodeContext()
         self.addCleanup(obj._delete_context)
         obj._execute_script(node_name, info)
-        self.assertTrue(remote_execute_mock.called)
+        remote_execute_mock.assert_called_once()
 
     def test_get_script(self):
         script_args = 'hello.bash'
@@ -276,7 +276,7 @@ class NodeContextTestCase(unittest.TestCase):
             'pwd': 'ubuntu',
         }]
         obj._get_client(node_name_args)
-        self.assertTrue(wait_mock.called)
+        wait_mock.assert_called_once()
 
     def test_get_server(self):
         self.test_context.init(self.attrs)
index 82a90b1..1ce30ea 100644 (file)
@@ -153,7 +153,7 @@ class TaskTestCase(unittest.TestCase):
         runner.get_result.return_value = []
         mock_base_runner.Runner.get.return_value = runner
         t._run([scenario], False, "yardstick.out")
-        self.assertTrue(runner.run.called)
+        runner.run.assert_called_once()
 
     @mock.patch.object(os, 'environ')
     def test_check_precondition(self, mock_os_environ):
index 98d967f..af4f0c8 100644 (file)
@@ -27,7 +27,7 @@ class AddMemoryLoadTestCase(unittest.TestCase):
         mock_from_node().execute.return_value = (0, '0 2048 512', '')
         obj = AddMemoryLoad(scenario_cfg, context_cfg)
         obj.run({})
-        self.assertTrue(mock_from_node.called)
+        mock_from_node.assert_called()
 
     @mock.patch('yardstick.ssh.SSH.from_node')
     def test_add_memory_load_without_load(self, mock_from_node):
@@ -41,7 +41,7 @@ class AddMemoryLoadTestCase(unittest.TestCase):
         }
         obj = AddMemoryLoad(scenario_cfg, context_cfg)
         obj.run({})
-        self.assertTrue(mock_from_node.called)
+        mock_from_node.assert_called_once()
 
     @mock.patch('yardstick.ssh.SSH.from_node')
     def test_add_memory_load_without_args(self, mock_from_node):
@@ -54,4 +54,4 @@ class AddMemoryLoadTestCase(unittest.TestCase):
         }
         obj = AddMemoryLoad(scenario_cfg, context_cfg)
         obj.run({})
-        self.assertTrue(mock_from_node.called)
+        mock_from_node.assert_called_once()
index a61195f..2964ecc 100644 (file)
@@ -23,4 +23,4 @@ class AttachVolumeTestCase(unittest.TestCase):
         args = {"options": options}
         obj = AttachVolume(args, {})
         obj.run({})
-        self.assertTrue(mock_attach_server_volume.called)
+        mock_attach_server_volume.assert_called_once()
index a50e752..270c9d3 100644 (file)
@@ -19,7 +19,7 @@ class CheckNumaInfoTestCase(unittest.TestCase):
         scenario_cfg = {'info1': {}, 'info2': {}}
         obj = CheckNumaInfo(scenario_cfg, {})
         obj.run({})
-        self.assertTrue(mock_check_vm2.called)
+        mock_check_vm2.assert_called_once()
 
     def test_check_vm2_status_length_eq_1(self):
         info1 = {
index 663ca5d..0b175fa 100644 (file)
@@ -26,4 +26,4 @@ class CreateFlavorTestCase(unittest.TestCase):
         args = {"options": options}
         obj = CreateFlavor(args, {})
         obj.run({})
-        self.assertTrue(mock_create_flavor.called)
+        mock_create_flavor.assert_called_once()
index ad4adee..cea60c3 100644 (file)
@@ -26,5 +26,5 @@ class CreateNetworkTestCase(unittest.TestCase):
         args = {"options": options}
         obj = CreateNetwork(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_create_neutron_net.called)
+        mock_get_neutron_client.assert_called_once()
+        mock_create_neutron_net.assert_called_once()
index 9a1611c..bea02a6 100644 (file)
@@ -24,4 +24,4 @@ class CreatePortTestCase(unittest.TestCase):
         args = {"options": options}
         obj = CreatePort(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
+        mock_get_neutron_client.assert_called_once()
index 1079214..3469a2a 100644 (file)
@@ -26,5 +26,5 @@ class CreateRouterTestCase(unittest.TestCase):
         args = {"options": options}
         obj = CreateRouter(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_create_neutron_router.called)
+        mock_get_neutron_client.assert_called_once()
+        mock_create_neutron_router.assert_called_once()
index b557673..21158ab 100644 (file)
@@ -26,5 +26,5 @@ class CreateSecGroupTestCase(unittest.TestCase):
         args = {"options": options}
         obj = CreateSecgroup(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_create_security_group_full.called)
+        mock_get_neutron_client.assert_called_once()
+        mock_create_security_group_full.assert_called_once()
index faee98f..9d6d8cb 100644 (file)
@@ -28,7 +28,7 @@ class CreateServerTestCase(unittest.TestCase):
         }
         obj = CreateServer(scenario_cfg, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
-        self.assertTrue(mock_get_glance_client.called)
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_create_instance_and_wait_for_active.called)
+        mock_get_nova_client.assert_called_once()
+        mock_get_glance_client.assert_called_once()
+        mock_get_neutron_client.assert_called_once()
+        mock_create_instance_and_wait_for_active.assert_called_once()
index 1536e83..554b88a 100644 (file)
@@ -28,5 +28,5 @@ class CreateSubnetTestCase(unittest.TestCase):
         args = {"options": options}
         obj = CreateSubnet(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_create_neutron_subnet.called)
+        mock_get_neutron_client.assert_called_once()
+        mock_create_neutron_subnet.assert_called_once()
index 4bfec32..30333dd 100644 (file)
@@ -94,7 +94,7 @@ class CreateVolumeTestCase(unittest.TestCase):
         args = {"options": options}
         scenario = create_volume.CreateVolume(args, {})
         scenario.run()
-        self.assertTrue(mock_create_volume.called)
-        self.assertTrue(mock_image_id.called)
-        self.assertTrue(mock_get_glance_client.called)
-        self.assertTrue(mock_get_cinder_client.called)
+        mock_create_volume.assert_called_once()
+        mock_image_id.assert_called_once()
+        mock_get_glance_client.assert_called_once()
+        mock_get_cinder_client.assert_called_once()
index e345afe..24dbf8a 100644 (file)
@@ -23,5 +23,5 @@ class DeleteFlavorTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteFlavor(args, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
-        self.assertTrue(mock_delete_flavor.called)
+        mock_get_nova_client.assert_called_once()
+        mock_delete_flavor.assert_called_once()
index be99719..3185ec5 100644 (file)
@@ -23,5 +23,5 @@ class DeleteFloatingIpTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteFloatingIp(args, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
-        self.assertTrue(mock_delete_floating_ip.called)
+        mock_get_nova_client.assert_called_once()
+        mock_delete_floating_ip.assert_called_once()
index eb3f9fc..e382d46 100644 (file)
@@ -24,6 +24,6 @@ class DeleteImageTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteImage(args, {})
         obj.run({})
-        self.assertTrue(mock_delete_image.called)
-        self.assertTrue(mock_image_id.called)
-        self.assertTrue(mock_get_glance_client.called)
+        mock_delete_image.assert_called_once()
+        mock_image_id.assert_called_once()
+        mock_get_glance_client.assert_called_once()
index 38cc929..6e790ba 100644 (file)
@@ -23,5 +23,5 @@ class DeleteKeypairTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteKeypair(args, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
-        self.assertTrue(mock_delete_keypair.called)
+        mock_get_nova_client.assert_called_once()
+        mock_delete_keypair.assert_called_once()
index 008ed91..9fd3185 100644 (file)
@@ -22,4 +22,4 @@ class DeletePortTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeletePort(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
+        mock_get_neutron_client.assert_called_once()
index 9b31566..d075108 100644 (file)
@@ -23,5 +23,5 @@ class DeleteRouterTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteRouter(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_delete_neutron_router.called)
+        mock_get_neutron_client.assert_called_once()
+        mock_delete_neutron_router.assert_called_once()
index e19c38d..0c9cf7c 100644 (file)
@@ -23,5 +23,5 @@ class DeleteRouterGatewayTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteRouterGateway(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_remove_gateway_router.called)
+        mock_get_neutron_client.assert_called_once()
+        mock_remove_gateway_router.assert_called_once()
index 6c4fdd5..9e9c5a5 100644 (file)
@@ -24,5 +24,5 @@ class DeleteRouterInterfaceTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteRouterInterface(args, {})
         obj.run({})
-        self.assertTrue(mock_get_neutron_client.called)
-        self.assertTrue(mock_remove_interface_router.called)
+        mock_get_neutron_client.assert_called_once()
+        mock_remove_interface_router.assert_called_once()
index dedce2d..eee565d 100644 (file)
@@ -23,5 +23,5 @@ class DeleteServerTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteServer(args, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
-        self.assertTrue(mock_delete_instance.called)
+        mock_get_nova_client.assert_called_once()
+        mock_delete_instance.assert_called_once()
index 2ea82e2..93f76e8 100644 (file)
@@ -23,5 +23,5 @@ class DeleteVolumeTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DeleteVolume(args, {})
         obj.run({})
-        self.assertTrue(mock_get_cinder_client.called)
-        self.assertTrue(mock_delete_volume.called)
+        mock_get_cinder_client.assert_called_once()
+        mock_delete_volume.assert_called_once()
index 34fbac6..9794d21 100644 (file)
@@ -23,4 +23,4 @@ class DetachVolumeTestCase(unittest.TestCase):
         args = {"options": options}
         obj = DetachVolume(args, {})
         obj.run({})
-        self.assertTrue(mock_detach_volume.called)
+        mock_detach_volume.assert_called_once()
index e9025f3..15a6f7c 100644 (file)
@@ -22,4 +22,4 @@ class GetFlavorTestCase(unittest.TestCase):
         args = {"options": options}
         obj = GetFlavor(args, {})
         obj.run({})
-        self.assertTrue(mock_get_flavor_by_name.called)
+        mock_get_flavor_by_name.assert_called_once()
index aa9f63e..879b2b9 100644 (file)
@@ -25,9 +25,9 @@ class GetMigrateTargetHostTestCase(unittest.TestCase):
                                      mock_get_nova_client):
         obj = GetMigrateTargetHost({}, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
-        self.assertTrue(mock_get_current_host_name.called)
-        self.assertTrue(mock_get_migrate_host.called)
+        mock_get_nova_client.assert_called_once()
+        mock_get_current_host_name.assert_called_once()
+        mock_get_migrate_host.assert_called_once()
 
     @mock.patch('{}.openstack_utils.get_nova_client'.format(BASE))
     def test_get_migrate_host(self, mock_get_nova_client):
@@ -39,5 +39,5 @@ class GetMigrateTargetHostTestCase(unittest.TestCase):
         mock_get_nova_client().hosts.list_all.return_value = [A('compute')]
         obj = GetMigrateTargetHost({}, {})
         host = obj._get_migrate_host('host5')
-        self.assertTrue(mock_get_nova_client.called)
+        mock_get_nova_client.assert_called()
         self.assertEqual(host, 'host4')
index 4b2132c..bea978b 100644 (file)
@@ -44,8 +44,8 @@ class GetNumaInfoTestCase(unittest.TestCase):
         }
         obj = GetNumaInfo(scenario_cfg, {})
         obj.run({})
-        self.assertTrue(mock_get_current_host_name.called)
-        self.assertTrue(mock_check_numa_node.called)
+        mock_get_current_host_name.assert_called_once()
+        mock_check_numa_node.assert_called_once()
 
     @mock.patch('yardstick.ssh.SSH.from_node')
     @mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE))
index 97b81ed..83ec903 100644 (file)
@@ -25,8 +25,8 @@ class GetServerTestCase(unittest.TestCase):
         }
         obj = GetServer(scenario_cfg, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
-        self.assertTrue(mock_get_server_by_name.called)
+        mock_get_nova_client.assert_called_once()
+        mock_get_server_by_name.assert_called_once()
 
     @mock.patch('yardstick.common.openstack_utils.get_nova_client')
     def test_get_server_with_id(self, mock_get_nova_client):
@@ -39,4 +39,4 @@ class GetServerTestCase(unittest.TestCase):
         mock_get_nova_client().servers.get.return_value = None
         obj = GetServer(scenario_cfg, {})
         obj.run({})
-        self.assertTrue(mock_get_nova_client.called)
+        mock_get_nova_client.assert_called()
index d663638..74144af 100644 (file)
@@ -65,7 +65,7 @@ class IperfTestCase(unittest.TestCase):
         p.target = mock_ssh.SSH.from_node()
 
         p.teardown()
-        self.assertTrue(mock_ssh.SSH.from_node().close.called)
+        mock_ssh.SSH.from_node().close.assert_called()
         mock_ssh.SSH.from_node().execute.assert_called_with("pkill iperf3")
 
     def test_iperf_successful_no_sla(self, mock_ssh):
index 1156b66..57dacbc 100644 (file)
@@ -21,30 +21,30 @@ class EnvCommandTestCase(unittest.TestCase):
     def test_do_influxdb(self, check_status_mock, start_async_task_mock):
         env = EnvCommand()
         env.do_influxdb({})
-        self.assertTrue(start_async_task_mock.called)
-        self.assertTrue(check_status_mock.called)
+        start_async_task_mock.assert_called_once()
+        check_status_mock.assert_called_once()
 
     @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
     @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
     def test_do_grafana(self, check_status_mock, start_async_task_mock):
         env = EnvCommand()
         env.do_grafana({})
-        self.assertTrue(start_async_task_mock.called)
-        self.assertTrue(check_status_mock.called)
+        start_async_task_mock.assert_called_once()
+        check_status_mock.assert_called_once()
 
     @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
     @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
     def test_do_prepare(self, check_status_mock, start_async_task_mock):
         env = EnvCommand()
         env.do_prepare({})
-        self.assertTrue(start_async_task_mock.called)
-        self.assertTrue(check_status_mock.called)
+        start_async_task_mock.assert_called_once()
+        check_status_mock.assert_called_once()
 
     @mock.patch('yardstick.cmd.commands.env.HttpClient.post')
     def test_start_async_task(self, post_mock):
         data = {'action': 'create_grafana'}
         EnvCommand()._start_async_task(data)
-        self.assertTrue(post_mock.called)
+        post_mock.assert_called_once()
 
     @mock.patch('yardstick.cmd.commands.env.HttpClient.get')
     @mock.patch('yardstick.cmd.commands.env.EnvCommand._print_status')
index f6f842e..9221676 100644 (file)
@@ -18,4 +18,4 @@ class TestcaseCommandsUT(unittest.TestCase):
     def test_do_list(self, mock_client, mock_print):
         mock_client.get.return_value = {'result': []}
         TestcaseCommands().do_list({})
-        self.assertTrue(mock_print.called)
+        mock_print.assert_called_once()