Merge "mock: Fixes mock.patch.multiple autospec"
This commit is contained in:
commit
cccaf73289
|
@ -157,7 +157,12 @@ class _patch(mock.mock._patch):
|
|||
isinstance(target, type))
|
||||
|
||||
new = super(_patch, self).__enter__()
|
||||
_lazy_autospec_method(new, original_attr, eat_self)
|
||||
|
||||
# NOTE(claudiub): mock.patch.multiple will cause new to be a
|
||||
# dict.
|
||||
mocked_method = (new[self.attribute] if isinstance(new, dict)
|
||||
else new)
|
||||
_lazy_autospec_method(mocked_method, original_attr, eat_self)
|
||||
return new
|
||||
else:
|
||||
return super(_patch, self).__enter__()
|
||||
|
|
|
@ -82,6 +82,13 @@ class MockSanityTestCase(testtools.TestCase):
|
|||
foo = Foo()
|
||||
self._check_autospeced_foo(foo)
|
||||
|
||||
def test_patch_autospec_multiple(self):
|
||||
with mock.patch.multiple(Foo, bar=mock.DEFAULT,
|
||||
classic_bar=mock.DEFAULT,
|
||||
static_bar=mock.DEFAULT):
|
||||
foo = Foo()
|
||||
self._check_autospeced_foo(foo)
|
||||
|
||||
@mock.patch.object(Foo, 'static_bar', autospec=False)
|
||||
@mock.patch.object(Foo, 'classic_bar', autospec=False)
|
||||
@mock.patch.object(Foo, 'bar', autospec=False)
|
||||
|
|
Loading…
Reference in New Issue