mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Add test for double patching instance methods (#11085)
This commit is contained in:
parent
f7fa62ef44
commit
5a718e918d
2 changed files with 16 additions and 0 deletions
|
@ -126,6 +126,20 @@ class WithTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(foo, {})
|
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):
|
class TestMockOpen(unittest.TestCase):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Added test demonstrating double-patching of an instance method. Patch by
|
||||||
|
Anthony Sottile.
|
Loading…
Add table
Add a link
Reference in a new issue