Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29a1e89

Browse filesBrowse files
gh-103329: Add regression test for PropertyMock with side effect (GH-103358)
(cherry picked from commit 26c6598) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
1 parent 70bc8c9 commit 29a1e89
Copy full SHA for 29a1e89

File tree

Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-1
lines changed

‎Lib/unittest/test/testmock/testhelpers.py

Copy file name to clipboardExpand all lines: Lib/unittest/test/testmock/testhelpers.py
+22-1Lines 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.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):
+1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.