How to patch a generator class method. For e.g. in class below, how would we patch get_changed_diff_patch method?
class PassiveJsonMixin(JsonMixin):
"""
passive items that do not have id/key
"""
def __init__(self, *args, **kwargs):
JsonMixin.__init__(self, *args, **kwargs)
# self.build_json()
pass
def get_changed_diff_patch(self, parent_hidden=False):
print ("From PassiveJsonMixin: get_changed_diff_patch")
return
yield
The usual approach
patch.object(mymod.PassiveJsonMixin, 'get_changed_diff_patch',wrapper(mymod.PassiveJsonMixin.get_changed_diff_patch) )
doesn't seem to work.
Expanding a bit on the answer, via using the with context: