Do not use contextlib.nested if only mock one function

Bug #1263602 reported by Guangya Liu (Jay Lau)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Undecided
Guangya Liu (Jay Lau)

Bug Description

There are some test cases in test_compute_mgr.py using contextlib.nested to mock up functions even there is only one function.

We should use mock.patch.object directly if only mock one function.

def test_init_instance_sets_building_error(self):
        with contextlib.nested( <<<<< No need use nested here
            mock.patch.object(self.compute, '_instance_update')
          ) as (
            _instance_update,
          ):

            instance = instance_obj.Instance(self.context)
            instance.uuid = 'foo'
            instance.vm_state = vm_states.BUILDING
            instance.task_state = None
            self.compute._init_instance(self.context, instance)
            call = mock.call(self.context, 'foo',
                             task_state=None,
                             vm_state=vm_states.ERROR)
            _instance_update.assert_has_calls([call])

Changed in nova:
assignee: nobody → Jay Lau (jay-lau-513)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/63670

Changed in nova:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/63670
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=8c359e0d0cf40b82b07ed1a30f6bfc00369892a6
Submitter: Jenkins
Branch: master

commit 8c359e0d0cf40b82b07ed1a30f6bfc00369892a6
Author: Jay Lau <email address hidden>
Date: Mon Dec 23 01:14:56 2013 -0500

    Do not use contextlib.nested if only mock one function

    There are some test cases in test_compute_mgr.py using contextlib.nested
    to mock up functions even there is only one function needs to be mocked.

    We should use mock.patch.object directly if only mock one function.

    Change-Id: I30f05d0dcb442d426358b673f0e638ace8b85e0e
    Closes-Bug: #1263602

Changed in nova:
status: In Progress → Fix Committed
Changed in nova:
milestone: none → icehouse-2
Thierry Carrez (ttx)
Changed in nova:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: icehouse-2 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.