mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
gh-103329: Add regression test for PropertyMock with side effect (GH-103358)
(cherry picked from commit 26c65980dc
)
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
This commit is contained in:
parent
70bc8c936d
commit
29a1e89c9f
2 changed files with 23 additions and 1 deletions
|
@ -1077,7 +1077,7 @@ class TestCallList(unittest.TestCase):
|
|||
p.stop()
|
||||
|
||||
|
||||
def test_propertymock_returnvalue(self):
|
||||
def test_propertymock_bare(self):
|
||||
m = MagicMock()
|
||||
p = PropertyMock()
|
||||
type(m).foo = p
|
||||
|
@ -1088,6 +1088,27 @@ class TestCallList(unittest.TestCase):
|
|||
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):
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Regression tests for the behaviour of ``unittest.mock.PropertyMock`` were added.
|
Loading…
Add table
Add a link
Reference in a new issue