8000 gh-103329: Add regression test for PropertyMock with side effect (#10… · python/cpython@26c6598 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26c6598

Browse files
authored
gh-103329: Add regression test for PropertyMock with side effect (#103358)
1 parent 91794e5 commit 26c6598

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Lib/test/test_unittest/testmock/testhelpers.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def test_propertymock(self):
10771077
p.stop()
10781078

10791079

1080-
def test_propertymock_returnvalue(self):
1080+
def test_propertymock_bare(self):
10811081
m = MagicMock()
10821082
p = PropertyMock()
10831083
type(m).foo = p
@@ -1088,6 +1088,27 @@ def test_propertymock_returnvalue(self):
10881088
self.assertNotIsInstance(returned, PropertyMock)
10891089

10901090

1091+
def test_propertymock_returnvalue(self):
1092+
m = MagicMock()
1093+
p = PropertyMock(return_value=42)
1094+
type(m).foo = p
1095+
1096+
returned = m.foo
1097+
p 8000 .assert_called_once_with()
1098+
self.assertEqual(returned, 42)
1099+
self.assertNotIsInstance(returned, PropertyMock)
1100+
1101+
1102+
def test_propertymock_side_effect(self):
1103+
m = MagicMock()
1104+
p = PropertyMock(side_effect=ValueError)
1105+
type(m).foo = p
1106+
1107+
with self.assertRaises(ValueError):
1108+
m.foo
1109+
p.assert_called_once_with()
1110+
1111+
10911112
class TestCallablePredicate(unittest.TestCase):
10921113

10931114
def test_type(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Regression tests for the behaviour of ``unittest.mock.PropertyMock`` were added.

0 commit comments

Comments
 (0)
0