Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a718e9

Browse files
asottilecjw296
authored andcommitted
Add test for double patching instance methods (#11085)
1 parent f7fa62e commit 5a718e9

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Lib/unittest/test/testmock/testwith.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ def test_dict_context_manager(self):
126126

127127
self.assertEqual(foo, {})
128128

129+
def test_double_patch_instance_method(self):
130+
class C:
131+
def f(self):
132+
pass
133+
134+
c = C()
135+
136+
with patch.object(c, 'f', autospec=True) as patch1:
137+
with patch.object(c, 'f', autospec=True) as patch2:
138+
c.f()
139+
self.assertEqual(patch2.call_count, 1)
140+
self.assertEqual(patch1.call_count, 0)
141+
c.f()
142+
self.assertEqual(patch1.call_count, 1)
129143

130144

131145
class TestMockOpen(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added test demonstrating double-patching of an instance method. Patch by
2+
Anthony Sottile.

0 commit comments

Comments
 (0)