Skip to content

Commit

Permalink
gh-103329: Add regression test for PropertyMock with side effect (#10…
Browse files Browse the repository at this point in the history
…3358)

Backports: 26c65980dc6d842879d133165bb7c461d98cc6c7
Signed-off-by: Chris Withers <chris@simplistix.co.uk>
  • Loading branch information
freakboy3742 authored and cjw296 committed Apr 16, 2023
1 parent 09b0b29 commit 1c7bfef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.d/2023-04-08-00-50-23.gh-issue-103329.M38tqF.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Regression tests for the behaviour of ``unittest.mock.PropertyMock`` were added.
23 changes: 22 additions & 1 deletion mock/tests/testhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def test_propertymock(self):
p.stop()


def test_propertymock_returnvalue(self):
def test_propertymock_bare(self):
m = MagicMock()
p = PropertyMock()
type(m).foo = p
Expand All @@ -1097,6 +1097,27 @@ def test_propertymock_returnvalue(self):
self.assertNotIsInstance(returned, PropertyMock)


def test_propertymock_returnvalue(self):
m = MagicMock()
p = PropertyMock(return_value=42)
type(m).foo = p

returned = m.foo
p.assert_called_once_with()
self.assertEqual(returned, 42)
self.assertNotIsInstance(returned, PropertyMock)


def test_propertymock_side_effect(self):
m = MagicMock()
p = PropertyMock(side_effect=ValueError)
type(m).foo = p

with self.assertRaises(ValueError):
m.foo
p.assert_called_once_with()


class TestCallablePredicate(unittest.TestCase):

def test_type(self):
Expand Down

0 comments on commit 1c7bfef

Please sign in to comment.