jeudi 26 mai 2016

Unable to mock function call in Python

I am writing unit tests for my application that uses the Facebook Ads api. I am trying to mock the remote create function using the following:

CustomAudience.remote_create = Mock(return_value="some value")

However when I call remote_create on an instance of CustomAudience it seems to call the actual function as I am getting an exception due to the api not being set. My understanding is that mocking CustomAudience.remote_create in this way should call a mock whenever this function is called on an instance.

I found that mocking functions in my own class in this way worked fine however it is not working with the remote_create function.

Are there some functions in Python that can't be mocked? Like how in Java you can't mock final classes?

Aucun commentaire:

Enregistrer un commentaire