diff options
author | Russell Keith-Magee <russell@keith-magee.com> | 2023-04-08 02:09:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-08 02:09:00 (GMT) |
commit | 26c65980dc6d842879d133165bb7c461d98cc6c7 (patch) | |
tree | 3ade99c9f2b08ceef11f1f5625cefec639863042 /Lib/test/test_unittest | |
parent | 91794e587306343619a451473efae22aa9f4b9bd (diff) | |
download | cpython-26c65980dc6d842879d133165bb7c461d98cc6c7.zip cpython-26c65980dc6d842879d133165bb7c461d98cc6c7.tar.gz cpython-26c65980dc6d842879d133165bb7c461d98cc6c7.tar.bz2 |
gh-103329: Add regression test for PropertyMock with side effect (#103358)
Diffstat (limited to 'Lib/test/test_unittest')
-rw-r--r-- | Lib/test/test_unittest/testmock/testhelpers.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_unittest/testmock/testhelpers.py b/Lib/test/test_unittest/testmock/testhelpers.py index 9e7ec5d..dc4d004 100644 --- a/Lib/test/test_unittest/testmock/testhelpers.py +++ b/Lib/test/test_unittest/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): |