Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sdague opened this issue Jul 10, 2015 · 3 comments
Closed

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

sdague opened this issue Jul 10, 2015 · 3 comments

Comments

@sdague
Copy link

sdague commented Jul 10, 2015

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.

@dtantsur
Copy link

Here is my reproducer for the failure: http://fpaste.org/242638/
Note that with spec=True method signature is not checked, so it's not literal replacement.

I was told by someone that the same regression happened between Python 3.4.0 and 3.4.2.

openstack-gerrit pushed a commit to openstack/nova that referenced this issue Jul 10, 2015
This includes 2 classes of fixes (and 1 skip) for mock.

The first is the change in allowed values for assert_has_calls -
testing-cabal/mock#263

The second is a yet unsolved bug around the use of autospec
testing-cabal/mock#264

The skip is because something has changed with mock.open that is
causing the vhduils test to fail. We don't know why, but it's one test
to skip.

This also includes a brute force fix for tox -e docs, because pip is
no longer respecting the sphinx pin in test requirements. This has to
be landed with the other changes because they won't work without it.

Change-Id: Id835d080a1ada52cbd3f24dad9bab5eeb2f29a54
Partial-Bug: 1473401
openstack-gerrit pushed a commit to openstack/openstack that referenced this issue Jul 10, 2015
Project: openstack/nova  4442979e71bb09ff9b71604c0dddd37c2bede04d

Fix for mock-1.1.0

This includes 2 classes of fixes (and 1 skip) for mock.

The first is the change in allowed values for assert_has_calls -
testing-cabal/mock#263

The second is a yet unsolved bug around the use of autospec
testing-cabal/mock#264

The skip is because something has changed with mock.open that is
causing the vhduils test to fail. We don't know why, but it's one test
to skip.

This also includes a brute force fix for tox -e docs, because pip is
no longer respecting the sphinx pin in test requirements. This has to
be landed with the other changes because they won't work without it.

Change-Id: Id835d080a1ada52cbd3f24dad9bab5eeb2f29a54
Partial-Bug: 1473401
@rbtcollins
Copy link
Member

This was reported upstream as http://bugs.python.org/issue23661 and I'm applying the patch and backporting now.

@rbtcollins
Copy link
Member

Fixed in Python 3.6 and in mock 1.1.3 [backwards compat bugfix].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants