diff options
author | Xtreak <tir.karthi@gmail.com> | 2019-03-29 02:38:43 +0530 |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-03-28 14:08:43 -0700 |
commit | 02b84cb1b4f5407309c81c8b1ae0397355d6e568 (patch) | |
tree | c7faa3554711f2a97b71c53699b19fb2f7f4581d /Lib/unittest/mock.py | |
parent | 3d78c4a6e5ae91eaf337b6f5cc6e8bb01af7c7b1 (diff) | |
download | cpython-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/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index fdde16be03..8684f1dfa5 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -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) |