mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Fix mock.patch.dict
to be stopped with mock.patch.stopall
(#17606)
As the function was not registering in the active patches, the mocks started by `mock.patch.dict` were not being stopped when `mock.patch.stopall` was being called.
This commit is contained in:
parent
1d0c5e16ea
commit
e131c9720d
3 changed files with 69 additions and 2 deletions
|
@ -1851,8 +1851,23 @@ class _patch_dict(object):
|
|||
self._unpatch_dict()
|
||||
return False
|
||||
|
||||
start = __enter__
|
||||
stop = __exit__
|
||||
|
||||
def start(self):
|
||||
"""Activate a patch, returning any created mock."""
|
||||
result = self.__enter__()
|
||||
_patch._active_patches.append(self)
|
||||
return result
|
||||
|
||||
|
||||
def stop(self):
|
||||
"""Stop an active patch."""
|
||||
try:
|
||||
_patch._active_patches.remove(self)
|
||||
except ValueError:
|
||||
# If the patch hasn't been started this will fail
|
||||
pass
|
||||
|
||||
return self.__exit__()
|
||||
|
||||
|
||||
def _clear_dict(in_dict):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue