Skip to content

Instantly share code, notes, and snippets.

@drFabio
Last active February 6, 2016 13:40
Show Gist options
  • Save drFabio/e7c09f3d44254fb62f3d to your computer and use it in GitHub Desktop.
Save drFabio/e7c09f3d44254fb62f3d to your computer and use it in GitHub Desktop.
Utility to simplify patch.objec wen it behaves as a spy
from unittest.mock import patch
def spy(target, attribute, **kwargs):
if kwargs.get('wraps') is None:
kwargs['wraps'] = getattr(target, attribute)
return patch.object(target, attribute , **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment