Skip to content

Instantly share code, notes, and snippets.

@omaciel
Created October 9, 2014 18:56
Show Gist options
  • Save omaciel/5f51c851db278a72ed5d to your computer and use it in GitHub Desktop.
Save omaciel/5f51c851db278a72ed5d to your computer and use it in GitHub Desktop.
Playing with Mock
import mock
class Car(object):
def shift_down(self):
print "Down"
def shift_up(self):
print "Up"
with mock.patch('__main__.Car') as mocked_car:
my_car = mocked_car()
my_car.shift_up()
my_car.shift_down()
my_car.foo()
print my_car.method_calls
def hello():
return "Hello"
with mock.patch.object(Car, 'shift_down') as mocked_shift_down:
mocked_shift_down.return_value = hello()
my_car = Car()
my_car.shift_up()
print my_car.shift_down()
my_car.foo()
print my_car.method_calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment