jeudi 1 septembre 2016

ImportError for a custom TestCase child using python manage.py test app

I want to use a generic custom TestCase for my_app that is currently running fine. I have the following simplified directory architecture :

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

The CustomTest class look like this :

from django.test import SimpleTestCase
from django.test.client import Client


class LionessTest(SimpleTestCase):

    def setUp(self):
        self.client = Client()

The test I want to launch is the following one :

from tests.test_views.custom_test import CustomTest

class Test_Login(CustomTest):

    def test_thing(self):
        self.assertTrue(True)

The 'my_app' directory is in the pythonpath and there is an init.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 :

python manage.py test my_app

I get the following error :

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 <module>
    from tests.tests_views.my_app_test.custom_test import CustomTest
ImportError: No module named tests_views.custom_test

Any idea ?

Aucun commentaire:

Enregistrer un commentaire