samedi 27 août 2016

Installed app in Django not found when running tests

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:

SystemError: Parent module '' not loaded, cannot perform relative import

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:

ImportError: No module named 'menu'

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.

menu/tests.py

import unittest

from menu import views

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

    def test_menu(self):
        pass

if __name__ == '__main__':
    unittest.main()

settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'menu',
    'django_nose'
)

Aucun commentaire:

Enregistrer un commentaire