title: Transitive import error: ModuleNotFoundError: No module named '...'
body: <p>I'm confused now.  Here is the project tree:</p>
  
  <pre><code>project
  - source
  - - lib
  - - - __init__.py
  - - - utils.py
  - - - stats.py
  - test
  - - lib
  - - - test_stats.py
  </code></pre>
  
  <p><code>stats.py</code> has <code>import utils</code>, which indeed works if one executes <code>stats.py</code> itself.  Now <code>test_stats.py</code> has <code>import lib.stats</code> but that results in the <code>ModuleNotFoundError: No module named 'utils'</code> error if executed as <code>PYTHONPATH=source pytest</code> in the <code>project</code> directory:</p>
  
  <pre><code>==================================== ERRORS ====================================
  ___________________ ERROR collecting test/lib/test_stats.py ___________________
  ImportError while importing test module '/lib/test_stats.py'.
  Hint: make sure your test modules/packages have valid Python names.
  Traceback:
  test/lib/test_stats.py:40: in &lt;module&gt;
      import lib.stats
  source/lib/__init__.py:42: in &lt;module&gt;
      from .stats import Stats
  source/lib/stats.py:40: in &lt;module&gt;
      import utils
  E   ModuleNotFoundError: No module named 'utils'
  !!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
  =========================== 1 error in 0.19 seconds ============================
  </code></pre>
  
  <p>What's going on and how to properly execute tests with such directory structure? </p>
  
  <p><strong>P.S.</strong>  I'm aware of (development mode) <code>pip install ...</code> and <code>tox</code> tricks (for module search path), but I would like to understand whether they are absolutely necessary to get this going or I already assume something wrong in this simple setup.</p>