Python Mock function return always False
<p>I try to add unit test in python in function that save stats in a file</p>

<p>Here is the function for saving</p>

<pre><code>def save_file_if_necessary(file_path, content, current_time, mode="w", delta_time=60, force=False):
    if file_path not in file_save or current_time - file_save[file_path] &gt;= delta_time or force:
        with codecs.open(file_path, mode, encoding="utf-8") as written_file:
            written_file.write(content)
            file_save[file_path] = time.time()
            print "yes"
            return True
    else:
        print "not necessary"
        return False
</code></pre>

<p>I make a call of this function like that</p>

<pre><code>def test_function():
    bot_url_dic = {"seven1": 10,
                   "seven2": 20
                  }
    save_file_if_necessary(os.path.join("./", "recipients.bots"),json.dumps(bot_url_dic, ensure_ascii=False, indent=4), time.time())
</code></pre>

<p>And i made some unittest with mock to test if the function is called</p>

<pre><code>from test import save_file_if_necessary, test_function

    def test_call_save_file_if_necessary(self):
        """test function to test add in list."""
        ip_dic = ["seven1", "seven2", "seven3"]
        save_file_if_necessary = Mock()

        test_function()
        self.assertTrue(save_file_if_necessary.called)
</code></pre>

<p>But the problem is Mock is always return False but the function is called at least one time.</p>

<pre><code>self.assertTrue(save_file_if_necessary.called)
AssertionError: False is not true
</code></pre>

<p>(python version 2.7.6)</p>