Skip to content

Instantly share code, notes, and snippets.

@andrewkowalik
Last active August 16, 2016 22:25
Show Gist options
  • Save andrewkowalik/c32e9dd92a3b7e5b3c7765e3b9c3d1fa to your computer and use it in GitHub Desktop.
Save andrewkowalik/c32e9dd92a3b7e5b3c7765e3b9c3d1fa to your computer and use it in GitHub Desktop.
import mock
class foobar(object):
def show_me(self):
print('the money')
no_spec_mock = mock.MagicMock()
no_spec_mock.foobar.called
# False
no_spec_mock.foobar()
no_spec_mock.foobar.called
# True
spec_mock = mock.MagicMock(spec=foobar)
spec_mock.foobar()
# AttributeError: Mock object has no attribute 'foobar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment