From 53e35b37372d8a543086a2117551fe0e2b6156b9 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 2 Mar 2016 14:21:31 +0100 Subject: [PATCH] Fix test_create_volume_flow test issue One of the tests in cinder/tests/unit/volume/flows/test_create_volume_flow.py incorrectly mocks time.time function which means that when there's a call to time.time() it will raise an error because real time function doesn't expect any arguments but the mock method does expect self as an argument. For some reason time.time function does not get called on every test run, but when it does get called it will fail. This patch fixes this by binding the mock method to the current self instance. Change-Id: Ia70e51719abb9a6ed357802446847ffa81d7427e --- cinder/tests/unit/volume/flows/test_create_volume_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/volume/flows/test_create_volume_flow.py b/cinder/tests/unit/volume/flows/test_create_volume_flow.py index 4302611b1..93461ce0c 100644 --- a/cinder/tests/unit/volume/flows/test_create_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_create_volume_flow.py @@ -42,7 +42,6 @@ class CreateVolumeFlowTestCase(test.TestCase): def setUp(self): super(CreateVolumeFlowTestCase, self).setUp() self.ctxt = context.get_admin_context() - self.counter = float(0) # Ensure that time.time() always returns more than the last time it was # called to avoid div by zero errors. @@ -50,10 +49,11 @@ class CreateVolumeFlowTestCase(test.TestCase): @mock.patch('cinder.objects.Volume.get_by_id') @mock.patch('cinder.volume.utils.extract_host') - @mock.patch('time.time', side_effect=time_inc) + @mock.patch('time.time') @mock.patch('cinder.objects.ConsistencyGroup.get_by_id') def test_cast_create_volume(self, consistencygroup_get_by_id, mock_time, mock_extract_host, volume_get_by_id): + mock_time.side_effect = self.time_inc volume = fake_volume.fake_volume_obj(self.ctxt) volume_get_by_id.return_value = volume props = {} -- 2.45.2