mirror of
https://github.com/python/cpython.git
synced 2025-09-08 18:01:44 +00:00
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
This commit is contained in:
parent
3d78c4a6e5
commit
02b84cb1b4
3 changed files with 15 additions and 3 deletions
|
@ -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())
|
||||
|
||||
|
||||
def test_stop_idempotent(self):
|
||||
# bpo-36366: calling stop on an already stopped patch will return None.
|
||||
patcher = patch(foo_name, 'bar', 3)
|
||||
|
||||
# calling stop without start used to produce a very obscure error
|
||||
self.assertRaises(RuntimeError, patcher.stop)
|
||||
patcher.start()
|
||||
patcher.stop()
|
||||
self.assertIsNone(patcher.stop())
|
||||
|
||||
|
||||
def test_patchobject_start_stop(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue