summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2018-12-12 07:56:35 (GMT)
committerChris Withers <chris@withers.org>2018-12-12 07:56:35 (GMT)
commit5a718e918db6211b633a7afb2bf537eb5b56cb1b (patch)
tree4d143852021dc6a5bd21ffe4f67257eb7e7528d3 /Lib/unittest
parentf7fa62ef4422c9deee050a794fd8504640d9f8f4 (diff)
downloadcpython-5a718e918db6211b633a7afb2bf537eb5b56cb1b.zip
cpython-5a718e918db6211b633a7afb2bf537eb5b56cb1b.tar.gz
cpython-5a718e918db6211b633a7afb2bf537eb5b56cb1b.tar.bz2
Add test for double patching instance methods (#11085)
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/test/testmock/testwith.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testwith.py b/Lib/unittest/test/testmock/testwith.py
index 43b36a1..ec4e540 100644
--- a/Lib/unittest/test/testmock/testwith.py
+++ b/Lib/unittest/test/testmock/testwith.py
@@ -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):