mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +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
|
@ -1398,7 +1398,7 @@ class _patch(object):
|
|||
def __exit__(self, *exc_info):
|
||||
"""Undo the patch."""
|
||||
if not _is_started(self):
|
||||
raise RuntimeError('stop called on unstarted patcher')
|
||||
return
|
||||
|
||||
if self.is_local and self.temp_original is not DEFAULT:
|
||||
setattr(self.target, self.attribute, self.temp_original)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue