Skip to content

Commit 1c7bfef

Browse files
freakboy3742cjw296
authored andcommitted
gh-103329: Add regression test for PropertyMock with side effect (#103358)
Backports: 26c65980dc6d842879d133165bb7c461d98cc6c7 Signed-off-by: Chris Withers <chris@simplistix.co.uk>
1 parent 09b0b29 commit 1c7bfef

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Regression tests for the behaviour of ``unittest.mock.PropertyMock`` were added.

mock/tests/testhelpers.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def test_propertymock(self):
10861086
p.stop()
10871087

10881088

1089-
def test_propertymock_returnvalue(self):
1089+
def test_propertymock_bare(self):
10901090
m = MagicMock()
10911091
p = PropertyMock()
10921092
type(m).foo = p
@@ -1097,6 +1097,27 @@ def test_propertymock_returnvalue(self):
10971097
self.assertNotIsInstance(returned, PropertyMock)
10981098

10991099

1100+
def test_propertymock_returnvalue(self):
1101+
m = MagicMock()
1102+
p = PropertyMock(return_value=42)
1103+
type(m).foo = p
1104+
1105+
returned = m.foo
1106+
p.assert_called_once_with()
1107+
self.assertEqual(returned, 42)
1108+
self.assertNotIsInstance(returned, PropertyMock)
1109+
1110+
1111+
def test_propertymock_side_effect(self):
1112+
m = MagicMock()
1113+
p = PropertyMock(side_effect=ValueError)
1114+
type(m).foo = p
1115+
1116+
with self.assertRaises(ValueError):
1117+
m.foo
1118+
p.assert_called_once_with()
1119+
1120+
11001121
class TestCallablePredicate(unittest.TestCase):
11011122

11021123
def test_type(self):

0 commit comments

Comments
 (0)