Skip to content

mock.patch.object ... autospec=True does not work #264

@sdague

Description

@sdague
def test_serialized_with_retry_socket_reset_reraised(self):
    exc = socket.error()
    exc.errno = errno.ECONNRESET
    plugin = 'glance'
    fn = 'download_vhd'
    num_retries = 1
    callback = None
    retry_cb = mock.Mock()
    with mock.patch.object(self.session, 'call_plugin_serialized',
            autospec=True) as call_plugin_serialized:
        call_plugin_serialized.side_effect = exc
        self.assertRaises(exception.PluginRetriesExceeded,
                self.session.call_plugin_serialized_with_retry, plugin, fn,
                num_retries, callback, retry_cb)
        call_plugin_serialized.assert_called_with(plugin, fn)
        self.assertEqual(2, call_plugin_serialized.call_count)

From https://github.com/openstack/nova/blob/master/nova/tests/unit/virt/xenapi/client/test_session.py#L143-L158

No longer works.

The current work around is change 'autospec' to 'spec'. Not sure the root issue, lifeless sorted out the fix. This bug is here for tracking the resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions