Skip to content

Instantly share code, notes, and snippets.

@rdammkoehler
Created January 20, 2016 20:45
Show Gist options
  • Save rdammkoehler/0f62d802b0a06c8c4c5a to your computer and use it in GitHub Desktop.
Save rdammkoehler/0f62d802b0a06c8c4c5a to your computer and use it in GitHub Desktop.
Mock That Monkey
In [42]: class Foo(object):
....: def bar(self):
....: return 'x'
....:
In [43]: class Baz(object):
....: def biz(self):
....: return Foo().bar()
....:
In [44]: Baz().biz()
Out[44]: 'x'
In [45]: with mock.patch.object(Foo, 'bar', return_value='y') as fu:
print(Baz().biz())
....:
y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment