lundi 18 juin 2018

Mock a function that calls another one which needs to be mocked (MagicMock)

I have a Python class "Sample" which has a method (request_info) doing a POST request. In this method, I call another function (get_credentials) which gets credentials. I need to do a test on request_info method with pytest and MagicMock. However, if I want to test this latter, I have to mock the get_credentials function. Is there a way to mock get_credentials before mocking get_credentials directly into the code by using for example pytest fixtures or something else?

Aucun commentaire:

Enregistrer un commentaire