summaryrefslogtreecommitdiff
path: root/oslotest
diff options
context:
space:
mode:
authorClaudiu Belu <cbelu@cloudbasesolutions.com>2018-03-28 01:07:18 -0700
committerClaudiu Belu <cbelu@cloudbasesolutions.com>2018-03-28 01:14:44 -0700
commitbb78b84c3fc8485e590f2c925c07731a9740a852 (patch)
treef9c0851afd3d0a62e613e1939690df6ab7ebdfa4 /oslotest
parent9460095d7dabf6c6e1faa0565cf816f4d785ac69 (diff)
downloadoslotest-bb78b84c3fc8485e590f2c925c07731a9740a852.tar.gz
mock: Properly patch mock.MagicMock3.4.1
MockAutospecFixture should patch both internal and external usages of MagicMock (mock.MagicMock and mock.mock.MagicMock). However, only the internal one is patched properly. Related-Bug: #1735588 Change-Id: Ib9709f1cf5dbed4792f5dd7c49d8f9c77f04419f
Diffstat (limited to 'oslotest')
-rw-r--r--oslotest/mock_fixture.py2
-rw-r--r--oslotest/tests/unit/test_mock_fixture.py10
2 files changed, 9 insertions, 3 deletions
diff --git a/oslotest/mock_fixture.py b/oslotest/mock_fixture.py
index fb9d008..ba53dd8 100644
--- a/oslotest/mock_fixture.py
+++ b/oslotest/mock_fixture.py
@@ -106,7 +106,7 @@ class MockAutospecFixture(fixtures.Fixture):
# patch both external and internal usage of Mock / MagicMock.
self.useFixture(fixtures.MonkeyPatch('mock.Mock', _AutospecMock))
self.useFixture(fixtures.MonkeyPatch('mock.mock.Mock', _AutospecMock))
- self.useFixture(fixtures.MonkeyPatch('mock.mock.MagicMock',
+ self.useFixture(fixtures.MonkeyPatch('mock.MagicMock',
_AutospecMagicMock))
self.useFixture(fixtures.MonkeyPatch('mock.mock.MagicMock',
_AutospecMagicMock))
diff --git a/oslotest/tests/unit/test_mock_fixture.py b/oslotest/tests/unit/test_mock_fixture.py
index 73afe8b..c5175b7 100644
--- a/oslotest/tests/unit/test_mock_fixture.py
+++ b/oslotest/tests/unit/test_mock_fixture.py
@@ -70,11 +70,17 @@ class MockSanityTestCase(testtools.TestCase):
# assert that AttributeError is raised if the method does not exist.
self.assertRaises(AttributeError, getattr, foo, 'lish')
- def test_mock_autospec_all_members(self):
+ def _check_mock_autospec_all_members(self, mock_cls):
for spec in [Foo, Foo()]:
- foo = mock.Mock(autospec=spec)
+ foo = mock_cls(autospec=spec)
self._check_autospeced_foo(foo)
+ def test_mock_autospec_all_members(self):
+ self._check_mock_autospec_all_members(mock.Mock)
+
+ def test_magic_mock_autospec_all_members(self):
+ self._check_mock_autospec_all_members(mock.MagicMock)
+
@mock.patch.object(Foo, 'static_bar')
@mock.patch.object(Foo, 'classic_bar')
@mock.patch.object(Foo, 'bar')