--- mock.py.orig 2014-04-04 14:09:06.000000000 +0900 +++ mock.py 2014-06-02 18:36:41.965076854 +0900 @@ -1597,6 +1597,8 @@ `patch.TEST_PREFIX` for choosing which methods to wrap. """ + _active_patches = set() + def __init__(self, in_dict, values=(), clear=False, **kwargs): if isinstance(in_dict, basestring): in_dict = _importer(in_dict) @@ -1645,6 +1647,7 @@ try: original = in_dict.copy() + self._active_patches.add(self) except AttributeError: # dict like object with no copy method # must support iteration over keys @@ -1672,6 +1675,7 @@ try: in_dict.update(original) + self._active_patches.discard(self) except AttributeError: for key in original: in_dict[key] = original[key] @@ -1699,6 +1703,8 @@ """Stop all active patches.""" for patch in list(_patch._active_patches): patch.stop() + for patch in list(_patch_dict._active_patches): + patch.stop() patch.object = _patch_object