我无法在我的测试目录中导入我的模型,这是我的错误:
======================================================================
ERROR: tests.test_views (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_views
Traceback (most recent call last):
File "C:\Python27\lib\unittest\loader.py", line 254, in _find_tests
module = self._get_module_from_name(name)
File "C:\Python27\lib\unittest\loader.py", line 232, in _get_module_from_name
__import__(name)
File "c:\wamp\www\km0\tests\test_views.py", line 3, in <module>
from .models import Entreprise
File "c:\wamp\www\km0\tests\models.py", line 6, in <module>
class Entreprise(models.Model):
File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\ba
se.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class tests.models.Entreprise doesn't declare an explicit ap
p_label and isn't in an application in INSTALLED_APPS.
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
Preserving test database for alias 'default' ('test_km0')...
我做了一些研究,但找不到答案......
test_views.py:
from django.test import TestCase
import unittest
from .models import Entreprise
class Km0ViewsTestCase(TestCase):
def test_cart(self):
resp = self.client.get('/fr/cart/')
self.assertEqual(resp.status_code, 200)
resp = self.client.get('/en/cart/')
self.assertEqual(resp.status_code, 200)
resp = self.client.get('/de/cart/')
self.assertEqual(resp.status_code, 200)
我的目录: my directory
提前感谢您的帮助!
答案 0 :(得分:4)
您的测试目录通常不需要models.py
。
如果您想从Entreprise
应用导入front
模型,请从
from .models import Entreprise
到
from front.models import Entreprise