title: Python Mock.Patch a function used at several places
body: <h3>This works:</h3>
  <p>I got my program:</p>
  <pre><code># module/core_functions.py
  
  def new_input(question):
      print(question)
      value = input(&quot;&gt;&quot;).strip()
      return value
  
  
  def main_function():
      #do things
      new_input(&quot;question1&quot;)
      #do other things
      new_input(&quot;question2&quot;)
      ...
  </code></pre>
  <p>I wrote an unittest:</p>
  <pre><code>import unittest
  from unittest.mock import patch, Mock
  from module.core_functions import main_function
  
  class MytestClass(unittest.TestCase):
  
      @patch('module.core_functions.new_input')
      def test_multiple_answer(self, mock_input):
          mock_input.return_value = Mock()
          mock_input.side_effect = ['Answer1', 'Answer2']
          result = main_function()
          self.assertIn('ExpectedResult', result)
  </code></pre>
  <p>This works perfectly fine (I use <code>nose2</code> to run all my tests).</p>
  <h3>Now this is not working:</h3>
  <p>As my code is getting bigger and bigger, I would like to involve other people in my project and I need to modularise my functions to make modification easier and cleaner.</p>
  <p>So I put the <code>new_input</code> function in a new file <code>module/io.py</code> and I got a new subfunctions:</p>
  <pre><code># module/subfunctions.py
  from module.io import new_input
  
  def subfunction():
      # do things
      new_input(&quot;question&quot;)
      # do things
      return things
  </code></pre>
  <p>And my core program evolved to:</p>
  <pre><code># module/core_functions.py
  from module.io import new_input
  from module.subfunctions import subfunction
  
  def main_function():
      #do things
      new_input(&quot;question1&quot;)
      #do other things
      subfuntion()
      ...
  </code></pre>
  <p>So the problem is that <strong>the function to mock is in several places</strong>: in the main function and in some subfunctions.
  I can't find a way to have my unittest working (I can't predict if AnswerX will be needed in the main function or in one subfunction).</p>
  <p>Do you have any idea how can I fix my test so it works?
  Thank you (I hope I've been rather clear).</p>
  <h3>Edit:</h3>
  <p>I tried something like:</p>
  <pre><code>@patch('module.core_functions.new_input')
  @patch('module.subfunctions.new_input')
  def test_multiple_answer(self, mock_input):
      mock_input.return_value = Mock()
      mock_input.side_effect = ['Answer1', 'Answer2']
      result = main_function()
      self.assertIn('ExpectedResult', result)
  </code></pre>
  <p>But I got the error: <code>TypeError: test_multiple_answer() takes 2 positional arguments but 3 were given</code>.</p>