]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103329: Add regression test for PropertyMock with side effect (#103358)
authorRussell Keith-Magee <russell@keith-magee.com>
Sat, 8 Apr 2023 02:09:00 +0000 (10:09 +0800)
committerGitHub <noreply@github.com>
Sat, 8 Apr 2023 02:09:00 +0000 (20:09 -0600)
Lib/test/test_unittest/testmock/testhelpers.py
Misc/NEWS.d/next/Tests/2023-04-08-00-50-23.gh-issue-103329.M38tqF.rst [new file with mode: 0644]

index 9e7ec5d62d5da2074dcb9f2397f8e721447069e5..dc4d004cda8a75872c3c9adbf5d17834b5ed74ff 100644 (file)
@@ -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):
diff --git a/Misc/NEWS.d/next/Tests/2023-04-08-00-50-23.gh-issue-103329.M38tqF.rst b/Misc/NEWS.d/next/Tests/2023-04-08-00-50-23.gh-issue-103329.M38tqF.rst
new file mode 100644 (file)
index 0000000..79448ed
--- /dev/null
@@ -0,0 +1 @@
+Regression tests for the behaviour of ``unittest.mock.PropertyMock`` were added.