summaryrefslogtreecommitdiff
path: root/Lib/unittest/test/testmock/testpatch.py
diff options
context:
space:
mode:
authorXtreak <tir.karthi@gmail.com>2019-03-29 02:38:43 +0530
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-03-28 14:08:43 -0700
commit02b84cb1b4f5407309c81c8b1ae0397355d6e568 (patch)
treec7faa3554711f2a97b71c53699b19fb2f7f4581d /Lib/unittest/test/testmock/testpatch.py
parent3d78c4a6e5ae91eaf337b6f5cc6e8bb01af7c7b1 (diff)
downloadcpython-git-02b84cb1b4f5407309c81c8b1ae0397355d6e568.tar.gz
bpo-36366: Return None on stopping unstarted patch object (GH-12472)
Return None after calling unittest.mock.patch.object.stop() regardless of whether the object was started. This makes the method idempotent. https://bugs.python.org/issue36366
Diffstat (limited to 'Lib/unittest/test/testmock/testpatch.py')
-rw-r--r--Lib/unittest/test/testmock/testpatch.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py
index c484adb605..2c14360b2d 100644
--- a/Lib/unittest/test/testmock/testpatch.py
+++ b/Lib/unittest/test/testmock/testpatch.py
@@ -772,10 +772,18 @@ class PatchTest(unittest.TestCase):
def test_stop_without_start(self):
+ # bpo-36366: calling stop without start will return None.
patcher = patch(foo_name, 'bar', 3)
+ self.assertIsNone(patcher.stop())
- # calling stop without start used to produce a very obscure error
- self.assertRaises(RuntimeError, patcher.stop)
+
+ def test_stop_idempotent(self):
+ # bpo-36366: calling stop on an already stopped patch will return None.
+ patcher = patch(foo_name, 'bar', 3)
+
+ patcher.start()
+ patcher.stop()
+ self.assertIsNone(patcher.stop())
def test_patchobject_start_stop(self):