i have a function like this, stored in file example.py:
def my_func(file):
conn = get_connection()
conn.upload_file(file)
conn.execute_file(file)
Now, i want to test it, so i`m using MagicMock in test_example.py like:
@mock.patch("example.get_connection")
def test_my_func(mock_conn):
mock_conn = MagickMock()
mock_conn.upload_file = MagickMock(return_value=True)
result= my_func("file.zip")
mock_conn.upload_file.assert_called()
Now, the test fails with error:
if self.call_count == 0:
msg = ("Expected '%s' to have been called." %
(self._mock_name or 'mock'))
> raise AssertionError(msg)
E AssertionError: Expected 'upload_file' to have been called.
When i debug the test, in example.py, MagickMocks attribute
called` is set to True after the call, but back in test_example.py it is False, and the test fails. What am i doing wrong?