diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-04-08 07:01:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-08 07:01:20 (GMT) |
commit | 29a1e89c9fbfaf409cee3d6fada9473a324ac1c8 (patch) | |
tree | 79c40394950fbb58554264bd8116d82e86fcd8af /Lib/unittest/test | |
parent | 70bc8c936dfbd936959efd32f0cddc2597598592 (diff) | |
download | cpython-29a1e89c9fbfaf409cee3d6fada9473a324ac1c8.zip cpython-29a1e89c9fbfaf409cee3d6fada9473a324ac1c8.tar.gz cpython-29a1e89c9fbfaf409cee3d6fada9473a324ac1c8.tar.bz2 |
gh-103329: Add regression test for PropertyMock with side effect (GH-103358)
(cherry picked from commit 26c65980dc6d842879d133165bb7c461d98cc6c7)
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/testmock/testhelpers.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py index 9e7ec5d..dc4d004 100644 --- a/Lib/unittest/test/testmock/testhelpers.py +++ b/Lib/unittest/test/testmock/testhelpers.py @@ -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): |