]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commit
Match mock.patch decorator with appropriate param
authorgit-harry <git-harry@live.co.uk>
Tue, 25 Nov 2014 14:20:26 +0000 (14:20 +0000)
committergit-harry <git-harry@live.co.uk>
Tue, 25 Nov 2014 14:31:21 +0000 (14:31 +0000)
commit65c1528b1c7d038778840d298a3da33f220c466e
tree69b6fc2f4e40bd7110a6c722dd09484284d6af3e
parent5f5cf928cf0ac72fc760ffdbafec049c110e532e
Match mock.patch decorator with appropriate param

mock.patch and mock.patch.object can be used as decorators for mocking
within the scope of the function they decorate. When there are multiple
decorators it is important the function parameters relate to the
corresponding patch objects i.e. that the parameter order matches the
decorator order.
It is easiest to explain this with an example:

@mock.patch.object(Foo, 'bar')
@mock.patch.object(SomeClass, 'some_method', some_function)
@mock.patch.object(AClass, 'a_method')
def test_some_stuff(self, mock_a_method, mock_bar):
    pass

So the decorator closest to the function definition must correspond to
the first (left-most) patch parameter. Note, if the decorator is given a
third argument, the kwarg new, then the decorated function is not
passed an extra argument by that decorator.

Change-Id: I035d71cb3b81f0c8bfd83ed81d8426cb0df31c90
cinder/tests/test_nimble.py
cinder/tests/test_volume.py