I'm having trouble replacing a simple method that calls a function in another module. From what I understand of mocking, you have to reference the method being called (in it's context, and not the original). Below is a simplified version of what I'm running and hoping that it's something simple that I need to learn about mocks. Is patch intended to be used only for Class and Class methods or am I doing something else wrong here?
Thanks, Steve
myapp.models.py
from myapp.backends import get_backend
class BasicClass(models.Model):
@staticmethod
def basic_method()
be = get_backend()
print be
myapp.backends._init_.py
def get_backend():
return 'original value'
test.py
# Referencing the import in myapp.models.basic_class
# vs directly importing myapp.backends
# as indicated here:
# http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch
from myapp.models import get_backend
from myapp.models.basic_class import BasicClass
class ParsersTest(TestCase):
@patch('myapp.models.get_backend')
def test_simplified(self, moves_backend):
# Assertion fails
assert get_backend is moves_backend
# Assuming that assertion fails is why the original return value is always returned
moves_backend.return_value = 'new return value'
BasicClass.basic_method()