title: pytest mocker fixture mock module from where it is defined and not where it is used
body: <p>I have some utils function at <code>src/utils/helper.py</code></p>
  
  <p>Imagine I have a function called <code>func_a</code> in utils/helper.py and it is used at multiple places in my project.</p>
  
  <p>And every time I use it, I import it like this</p>
  
  <pre class="lang-py prettyprint-override"><code>from src.utils.helper import func_a
  </code></pre>
  
  <p>Now I want to mock this <code>func_a</code> in my tests.</p>
  
  <p>I want to create a fixture in conftest.py so that I don't need to write a mock function again and again for each test file.</p>
  
  <p>The problem is, in my mock function I CANNOT write like this.</p>
  
  <p><a href="https://pypi.org/project/pytest-mock/" rel="nofollow noreferrer">https://pypi.org/project/pytest-mock/</a></p>
  
  <pre><code>mocker.patch('src.utils.helper.func_a', return_value="some_value", autospec=True)
  </code></pre>
  
  <p>I have to write it like this for each test file</p>
  
  <pre><code>mocker.patch('src.pipeline.node_1.func_a', return_value="some_value", autospec=True)
  </code></pre>
  
  <p>As per the docs <a href="https://docs.python.org/3/library/unittest.mock.html#where-to-patch" rel="nofollow noreferrer">https://docs.python.org/3/library/unittest.mock.html#where-to-patch</a></p>
  
  <p>Since I am importing <code>func_a</code> like <code>from src.utils.helper import func_a</code> I have to mock where it is used and not where it is defined.</p>
  
  <p>But the problem with this approach is that I can not define it in my fixture in conftest.py</p>
  
  <p>Directory Structure</p>
  
  <pre><code>├── src
  │   ├── pipeline
  │   │   ├── __init__.py
  │   │   ├── node_1.py
  │   │   ├── node_2.py
  │   │   └── node_3.py
  │   └── utils
  │       ├── __init__.py
  │       └── helper.py
  └── tests
      ├── __init__.py
      ├── conftest.py
      └── pipeline
          ├── __init__.py
          ├── test_node_1.py
          ├── test_node_2.py
          └── test_node_3.py
  </code></pre>