]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add test for double patching instance methods (#11085)
authorAnthony Sottile <asottile@umich.edu>
Wed, 12 Dec 2018 07:56:35 +0000 (23:56 -0800)
committerChris Withers <chris@withers.org>
Wed, 12 Dec 2018 07:56:35 +0000 (07:56 +0000)
Lib/unittest/test/testmock/testwith.py
Misc/NEWS.d/next/Tests/2018-12-10-13-18-37.bpo-26704.DBAN4c.rst [new file with mode: 0644]

index 43b36a1199526122d2e252385fb35bac827f23a7..ec4e540dcfd941fe855d0b526a52fae24f88d53a 100644 (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):
diff --git a/Misc/NEWS.d/next/Tests/2018-12-10-13-18-37.bpo-26704.DBAN4c.rst b/Misc/NEWS.d/next/Tests/2018-12-10-13-18-37.bpo-26704.DBAN4c.rst
new file mode 100644 (file)
index 0000000..458f495
--- /dev/null
@@ -0,0 +1,2 @@
+Added test demonstrating double-patching of an instance method.  Patch by
+Anthony Sottile.