title: Importing modules from parent directory in Python 2.7
body: <p>I'm failing to import a module from a parent directory in 2.7 and I'm not sure why. Any help would be appreciated.</p>
  
  <h2>Directory Structure</h2>
  
  <p>I have a Python package with this directory structure:</p>
  
  <pre><code>source/
  |--foo/__init__.py
  |--foo/bar/__init__.py
  |--foo/bar/nested.py
  |--foo/top.py
  tests/
  |--helpers/__init__.py
  |--foo/__init__.py
  |--foo/bar/__init__.py
  |--foo/bar/nested_test.py
  |--foo/top_test.py
  setup.py
  setup.cfg
  tox.ini
  </code></pre>
  
  <h2>Configuration</h2>
  
  <p>I use <code>pytest</code> and <code>python setup.py test</code> almost interchangeably to run my tests with. In <code>tox.ini</code>, I have:</p>
  
  <pre><code>[tox]
  envlist = py27
  
  [testenv]
  commands = pytest
  deps = pytest
  
  [pytest]
  testpaths=tests
  </code></pre>
  
  <p>Note, that I don't actually use <code>tox</code> to run my tests.</p>
  
  <p>And in <code>setup.cfg</code>:</p>
  
  <pre><code>[aliases]
  test=pytest
  </code></pre>
  
  <p>I'm not 100% sure, but I think this setup means that when I run <code>python setup.py test</code>, it actually just runs <code>pytest</code>, so it <em>might</em> not be relevant to this question. </p>
  
  <h2>Question</h2>
  
  <p>In <code>foo/top_test.py</code>, I can <code>import tests.helpers</code>, but in <code>foo/bar/nested_test.py</code>, the same import raises an <code>ImportError</code> saying that the module was not found. </p>
  
  <p>Why is this and how can I fix it?</p>
  
  <h2>Attempts</h2>
  
  <p>I've attempted to run <code>pytest</code> and <code>python setup.py test</code> in a clean virtualenv after running <code>pip install pytest</code> and <code>pip install -r requirements.txt</code> (My <code>requirements.txt</code> is basically a blank file with <code>-e</code> and <code>-i</code> set to a private repo.</p>
  
  <p>Note: I can open up a <code>python</code> REPL from the root directory of the project and <code>import tests._helper</code> without any problems.</p>
  
  <p>I've also attempted to add <code>tests</code> and <code>tests.helpers</code> to the <code>tests_require</code> argument in the <code>setuptools.setup()</code> function in <code>setup.py</code>, but it looks like it attempts to install those from the remote index instead of using the local modules.</p>
  
  <p>I've also attempted appending to <code>sys.path</code> in my foo/bar/nested_test.py:</p>
  
  <pre><code>import os
  import sys
  
  sys.path.append(os.path.realpath('tests'))
  </code></pre>
  
  <h2>Other notes</h2>
  
  <ul>
  <li>I'm not willing to bundle my tests into the source directory into each package</li>
  <li>I'm unable to use python 3 at the moment</li>
  </ul>