Add test for double patching instance methods (#11085)

This commit is contained in:
Anthony Sottile 2018-12-11 23:56:35 -08:00 committed by Chris Withers
parent f7fa62ef44
commit 5a718e918d
2 changed files with 16 additions and 0 deletions

View File

@ -126,6 +126,20 @@ class WithTest(unittest.TestCase):
self.assertEqual(foo, {})
def test_double_patch_instance_method(self):
class C:
def f(self):
pass
c = C()
with patch.object(c, 'f', autospec=True) as patch1:
with patch.object(c, 'f', autospec=True) as patch2:
c.f()
self.assertEqual(patch2.call_count, 1)
self.assertEqual(patch1.call_count, 0)
c.f()
self.assertEqual(patch1.call_count, 1)
class TestMockOpen(unittest.TestCase):

View File

@ -0,0 +1,2 @@
Added test demonstrating double-patching of an instance method. Patch by
Anthony Sottile.