I have defined two functions in a utils file, one call the other inside it code. Like this:
utils.py
def huge_db_call():
return colossal_sql_query_what_i_dont_want_to_test
def main_function():
variable = huge_db_call()
some irrelevant stuff
But now I want to test it in a test class which test the whole utils file. The main problem is that the function which is in called in the main function is a huge db call what I must not run in test, under this circumstances i'd prefer to define an output value which could be called when the huge db call function doesn't do his things and return the predefined output in the test method. So far I've tried this:
test_utils.py
from mock import patch
class test():
@patch('huge_db_call')
def test_main_function(self, mock_huge_db_call):
right_response = -- the_right_main_function_output
reasonable_test_return = -- not_a_huge_db_call_but_a_controlled_test_case--
mock_huge_db_call.return_value = reasonable_test_return
response = utils.main_function()
self.assertEqual(response, right_response)
But with no success
Can anyone help me please?