← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1263602] [NEW] Do not use contextlib.nested if only mock one function

 

Public bug reported:

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])

** Affects: nova
     Importance: Undecided
     Assignee: Jay Lau (jay-lau-513)
         Status: In Progress

** Changed in: nova
     Assignee: (unassigned) => Jay Lau (jay-lau-513)

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1263602

Title:
  Do not use contextlib.nested if only mock one function

Status in OpenStack Compute (Nova):
  In Progress

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])

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1263602/+subscriptions


Follow ups

References