Importing modules fails in Codeship
<p>I have a repository with the following directory structure:</p>

<pre><code>repo_folder\
----src\
    ----__init__.py
    ----src1.py
    ----src2.py
    ----src3.py
----testing\
    ----specific_test.py
----requirements.txt
</code></pre>

<hr>

<p><code>specific_test.py</code> has on it's first lines:</p>

<pre><code>import os
import sys

sys.path.insert(0, os.path.dirname(os.getcwd()))
import src.src1
import src.src2
import src.src3

# lots of asserts
</code></pre>

<hr>

<p>When I run <code>specific_test.py</code> from within <code>testing</code> folder or from <code>repo_folder</code> folder it works, but <strong>only</strong> on my <strong>local machine.</strong></p>

<p>The problem is that when I try to run this from my <code>codeship</code> account, it gives me an <code>Import Error</code>.
The error looks like this:</p>

<ul>
<li><code>ImportError</code> while importing test module </li>
<li>ERROR collecting <code>testing/specific_test.py</code></li>
<li>No module named <code>src.src1</code></li>
<li>Make sure your test modules/packages have valid Python names.</li>
</ul>

<hr>

<p>Do you know what would the problem be?</p>

<p>Do you have suggestions for better alternatives?</p>

<p>This seems to be a pathing issue.  What seems to be happening on your local machine is you insert into your path your CWD, which is most likely returning as <code>repo_folder\</code>. from there, you can import your src files via <code>src.src1</code> because src is containe.  On your codeship account, the cwd (current working directory) is not correct, thus is cannot find the <code>src.</code> part of <code>src.src1</code>.  Check what the line <code>sys.path.insert(0, os.path.dirname(os.getcwd()))</code> returns, more importantly <code>os.path.dirname(os.getcwd())</code> and verify that it is leading to <code>repo_folder\</code></p>

python continuous-integration python-import importerror codeship