diff --git a/oslotest/mock_fixture.py b/oslotest/mock_fixture.py index 6596d01..fb9d008 100644 --- a/oslotest/mock_fixture.py +++ b/oslotest/mock_fixture.py @@ -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__() diff --git a/oslotest/tests/unit/test_mock_fixture.py b/oslotest/tests/unit/test_mock_fixture.py index a574e08..73afe8b 100644 --- a/oslotest/tests/unit/test_mock_fixture.py +++ b/oslotest/tests/unit/test_mock_fixture.py @@ -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)