Skip to content
Advertisement

Mock and patch class method and give its return value to another function

Here are my snippets

JavaScript

So I want to test this instantiate_config with pytest. Here is my try:

JavaScript

But this gives empty config dict. I don’t know is that possible – to mock Client().get_resources() to give it same value and that value to be passed automatically as argument to add_config_func. If it it not what is the best way to test instantiate_config function. Not sure is in clear or not, cuz it is a little bit long story

Advertisement

Answer

Your mock is already representing the method get_resources, and you have a typo in “returned_values”. Change to : client_mock.return_value = dummy_data

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement