summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-04-26 16:11:08 +0000
committerGerrit Code Review <review@openstack.org>2018-04-26 16:11:08 +0000
commit974666550e999676b89101a82cfa8007f7a8abf6 (patch)
treec06b764a7a1b6746205cbe89c653e694e19ec20c
parent9837c5ef986e77e41860da622e5dc3d3d7788d6d (diff)
parent6baff0eda4edbd8163426a2ac774514cabf99a3a (diff)
downloadoslotest-974666550e999676b89101a82cfa8007f7a8abf6.tar.gz
Merge "mock: Apply autospec to a mock's return_value"
-rw-r--r--oslotest/mock_fixture.py8
-rw-r--r--oslotest/tests/unit/test_mock_fixture.py1
2 files changed, 8 insertions, 1 deletions
diff --git a/oslotest/mock_fixture.py b/oslotest/mock_fixture.py
index ba53dd8..8636c28 100644
--- a/oslotest/mock_fixture.py
+++ b/oslotest/mock_fixture.py
@@ -44,13 +44,19 @@ class _AutospecMockMixin(object):
def __init__(self, *args, **kwargs):
super(_AutospecMockMixin, self).__init__(*args, **kwargs)
- self.__dict__['_autospec'] = kwargs.get('autospec')
+ autospec = kwargs.get('autospec')
+ self.__dict__['_autospec'] = autospec
_mock_methods = self.__dict__['_mock_methods']
if _mock_methods:
# this will allow us to be able to set _mock_check_sig if
# the spec_set argument has been given.
_mock_methods.append('_mock_check_sig')
+ # callable mocks with autospecs (e.g.: the given autospec is a class)
+ # should have their return values autospeced as well.
+ if autospec:
+ self.return_value.__dict__['_autospec'] = autospec
+
def __getattr__(self, name):
attr = super(_AutospecMockMixin, self).__getattr__(name)
diff --git a/oslotest/tests/unit/test_mock_fixture.py b/oslotest/tests/unit/test_mock_fixture.py
index c5175b7..e578fb4 100644
--- a/oslotest/tests/unit/test_mock_fixture.py
+++ b/oslotest/tests/unit/test_mock_fixture.py
@@ -74,6 +74,7 @@ class MockSanityTestCase(testtools.TestCase):
for spec in [Foo, Foo()]:
foo = mock_cls(autospec=spec)
self._check_autospeced_foo(foo)
+ self._check_autospeced_foo(foo())
def test_mock_autospec_all_members(self):
self._check_mock_autospec_all_members(mock.Mock)