ImportError for a custom SimpleTestCase child using python manage.py test app
<p>I want to use a generic custom TestCase for my_app that is currently running fine. I have the following simplified directory architecture :</p>

<pre><code>my_app
âââ tests
â   âââ __init__.py
â   âââ test_views
â       âââ __init__.py
â       âââ custom_test.py
â       âââ registration
â       â   âââ __init__.py
â       â   âââ test_login.py
âââ views
    |ââ __init__.py
    âââ registration
    â   âââ __init__.py
    â   âââ login.py
</code></pre>

<p>The CustomTest class look like this :</p>

<pre><code>from django.test import SimpleTestCase
from django.test.client import Client


class CustomTest(SimpleTestCase):

    def setUp(self):
        self.client = Client()
</code></pre>

<p>The test I want to launch is the following one :</p>

<pre><code>from tests.test_views.custom_test import CustomTest

class Test_Login(CustomTest):

    def test_thing(self):
        self.assertTrue(True)
</code></pre>

<p>The 'my_app' directory is in the pythonpath and there is an <strong>init</strong>.py file for every module. Django can find error in test_login.py (for example if I change CustomTest to something else that does not exists), so test_login.py is read before my real problem happens and it imports and uses CustomTest sucessfully. But when I want to launch the test with :</p>

<pre><code>python manage.py test my_app
</code></pre>

<p>I get the following error : </p>

<pre><code>ImportError: Failed to import test module: my_app.tests.test_views.registration.test_login
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "~/workspace/my_app/my_app/tests/test_views/registration/test_login.py", line 7, in &lt;module&gt;
    from tests.tests_views.my_app_test.custom_test import CustomTest
ImportError: No module named tests_views.my_app_test.custom_test
</code></pre>

<p>Any idea ?</p>

<p>put the application name on the left of import:</p>

<pre><code>from myapp.tests.test_views.custom_test import CustomTest
</code></pre>

python django testing