I know how to patch my methods:
@patch('common.connections.upload_image')
def test_upload(self, mocked_upload_image):
mocked_upload_image.return_value = 'Mocked url'
This will patch my method upload_image
in module connections
in folder common
(I am using Django, folder common
lies in root).
But I want to patch serializer from Django Rest framework, which lies in venv.lib.python2.7.site-packages.rest_framework.serializers.BaseSerializer.is_valid
So I tried:
@patch('venv.lib.python2.7.site-packages.rest_framework.serializers.BaseSerializer.is_valid')
def test_upload(self, mocked_is_valid):
mocked_is_valid.return_value = True # this doesn't work
But it doesn't work. Says ImportError: No module named venv
. My venv
folder lies in the same folder, where the above mentioned common
lies.
So how to patch this library method then?
Aucun commentaire:
Enregistrer un commentaire