title: Python imports for tests using nose - what is best practice for imports of modules above current package
body: <p>This is a question which is asked frequently in different forms, and often obtains "lol you're not doing it properly" responses. Pretty sure that's because there's a common sense scenario people (including me) are trying to use as an implementation, and the solution is not obvious (if you've not done it before).</p>
  
  <p>Would accept an answer which "lets the fly out of the bottle".</p>
  
  <p>Given</p>
  
  <pre><code>project/
      __init__.py
      /code
          __init__.py
          sut.py
      /tests
          __init__.py
          test_sut.py
  </code></pre>
  
  <p>Where tests_sut.py starts:</p>
  
  <pre><code>import code.sut
  </code></pre>
  
  <p>Running nosetests in the root dir leads to:</p>
  
  <pre><code>ImportError: No module named code.sut
  </code></pre>
  
  <p>Avenues traveled:</p>
  
  <p>a) do a relative using </p>
  
  <pre><code>from ..code import sut
  </code></pre>
  
  <p>b) add root of project to PYTHONPATH</p>
  
  <p>c) use the </p>
  
  <pre><code>sys.path.append
  </code></pre>
  
  <p>to add the .. path before the imports at the start of each test module.</p>
  
  <p>d) just remember to do a </p>
  
  <pre><code>setup.py 
  </code></pre>
  
  <p>on the project to install the modules into the site-packages before running tests.</p>
  
  <hr/>
  
  <p>So the requirement is to have tests located beneath the test package root which have access to the project. Each of the above don't feel "natural" to me, have proved problematic or seem like too much hard work!</p>
  
  <p>In java this works, but basically by dint of your build tool / IDE placing all your classes on the classpath. Perhaps the issue is I'm expecting "magic" from Python? Have noted in the Flask webframework tests, option d) seems to be preferred.</p>
  
  <p>In any case, statements below recommending a preferred solution would remove the feeling of "unnaturalness" in my own.</p>