title: pytest unable to mock the same module multiple times
body: <p>I'm tring to use mock to test a specific function, for some reasons it seems that I can't mock twice the same module and I don't understand why</p>
  <p>a.py</p>
  <pre><code>def a():
      return &quot;ok&quot;
  
  </code></pre>
  <p>b.py</p>
  <pre><code>    from sandbox.tests.a import a
      
      
      def b(la):
      
          for i in la:
              a()
      
          return &quot;b&quot;
      
      
      def c():
          a()
          return &quot;c&quot;
  
  </code></pre>
  <p>What I want to test is the amount of calls of <em>a</em> are made, so in my test I do :</p>
  <pre><code>
      from mock import patch
      
      
      @patch(&quot;sandbox.tests.a.a&quot;, return_value=&quot;mocked&quot;)
      def test_b(mock):
          from sandbox.tests.b import b
      
          b([&quot;1&quot;, &quot;2&quot;])
      
          assert mock.call_count == 2
      
      
      @patch(&quot;sandbox.tests.a.a&quot;, return_value=&quot;mocked2&quot;)
      def test_b_again(mock):
          from sandbox.tests.b import c
      
          c()
      
          assert mock.call_count == 1
  
  </code></pre>
  <p>If I run 1 test it works but when I run the 2 tests together I have this error :</p>
  <pre><code>E       AssertionError: assert 0 == 1
  E        +  where 0 = &lt;Mock name='test_2' id='4360227664'&gt;.call_count
  </code></pre>
  <p>Surprisingly if I print the output of the mock in each function b and c, the mock has the same ID :</p>
  <pre><code>a &lt;MagicMock name='a' id='4358021024'&gt; # function b
  a &lt;MagicMock name='a' id='4358021024'&gt; # function c 
  </code></pre>
  <p>I also tried to put a name on the mock but it stills gives the same id</p>
  <pre><code>
  @patch(&quot;sandbox.tests.a.a&quot;)
  def test_b(mock):
      mock = Mock(name=&quot;test_1&quot;, return_value=&quot;test_1&quot;)
      from sandbox.tests.b import b
  
      b([&quot;1&quot;, &quot;2&quot;])
  
      assert mock.call_count == 2
  
  
  @patch(&quot;sandbox.tests.a.a&quot;)
  def test_b_again(mock):
      mock = Mock(name=&quot;test_2&quot;, return_value=&quot;test_2&quot;)
      from sandbox.tests.b import c
  
      c()
  
      assert mock.call_count == 1
  </code></pre>
  <p>Is there an equivalent of jest.resetModules() or something so I can mock twice the same module ?</p>
  <p>Thanks</p>