summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py3
-rw-r--r--Lib/unittest/test/testmock/testhelpers.py11
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 0a9aece..ec17542 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2166,6 +2166,9 @@ class PropertyMock(Mock):
Fetching a `PropertyMock` instance from an object calls the mock, with
no args. Setting it calls the mock with the value being set.
"""
+ def _get_child_mock(self, **kwargs):
+ return MagicMock(**kwargs)
+
def __get__(self, obj, obj_type):
return self()
def __set__(self, obj, val):
diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py
index 3674778..a2ed100 100644
--- a/Lib/unittest/test/testmock/testhelpers.py
+++ b/Lib/unittest/test/testmock/testhelpers.py
@@ -831,5 +831,16 @@ class TestCallList(unittest.TestCase):
p.stop()
+ def test_propertymock_returnvalue(self):
+ m = MagicMock()
+ p = PropertyMock()
+ type(m).foo = p
+
+ returned = m.foo
+ p.assert_called_once_with()
+ self.assertIsInstance(returned, MagicMock)
+ self.assertNotIsInstance(returned, PropertyMock)
+
+
if __name__ == '__main__':
unittest.main()