Installed app in Django not found when running tests
<p>I have a pretty simple Django app, that I am trying to run unit tests on. In my tests.py file I am trying to import the parent apps views file. I tried 'from . import views' but got an error:</p>

<pre><code>SystemError: Parent module '' not loaded, cannot perform relative import
</code></pre>

<p>I read that when a relative path does not work, you can try using an absolute path so I tried 'from menu import views' but than got another error:</p>

<pre><code>ImportError: No module named 'menu'
</code></pre>

<p>When I run a local server for the application it works just fine. Its only when I run 'coverage run 'coverage run menu/tests.py'. Since it is running fine, and the module is in my setting's installed apps, Im not entirely sure why this is happening.</p>

<p>menu/tests.py</p>

<pre><code>import unittest

from menu import views

class ModelTestCase(unittest.TestCase):
    def setUp(self):
        pass

    def test_menu(self):
        pass

if __name__ == '__main__':
    unittest.main()
</code></pre>

<p>settings.py</p>

<pre><code>INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'menu',
    'django_nose'
)
</code></pre>

<p>Traceback</p>

<pre><code>timothybaney$ coverage run menu/tests.py
Traceback (most recent call last):
  File "menu/tests.py", line 3, in &lt;module&gt;
    from menu import views
ImportError: No module named 'menu'
</code></pre>

<p>It's not much information you gave us.. but when I take a look at the Traceback it says <code>File 'menu/tests.py'</code>. So if the views.py is also inside the menu Folder you just can write:</p>

<pre><code>import views
</code></pre>

<p>If the views.py is in the main folder you could write:</p>

<pre><code>from ..main import views   #replace 'main' with your folder name
</code></pre>

python django testing module