title: python mock import in imported module
body: <p>I'm trying to use unittest.mock to mock an import in a module under test.</p>
  <p>What I'm seeing is that although my module calls sleep 5 times the mock object I'm interacting with in the test function isn't what I'm expecting.</p>
  <p>I'm assuming I'm not doing something correctly. I did read the docs, but I'm sure I'm not doing this correctly.</p>
  <pre class="lang-py prettyprint-override"><code>&quot;&quot;&quot;example.py&quot;&quot;&quot;
  
  import time
  
  
  def mycode():
      time.sleep(10)
      time.sleep(10)
      time.sleep(10)
      time.sleep(10)
      time.sleep(10)
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>&quot;&quot;&quot;test_example.py&quot;&quot;&quot;
  
  import example
  
  from unittest.mock import patch
  
  
  @patch(&quot;example.time.sleep&quot;)
  def test_example(mock_time):
      example.mycode()
      assert mock_time.call_count == 5
  </code></pre>