Django使用manage.py test错误解决

>python manage.py test polls


Creating test database for alias 'default'...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: mysite_project.polls.tests (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: mysite_project.polls.tests
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 "D:\Python\Djangostudy\mysite_project\polls\tests.py", line 8, in <module>
from .models import Question
File "D:\Python\Djangostudy\mysite_project\polls\models.py", line 14, in <module>
class Question(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 118, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class mysite_project.polls.models.Question doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
Destroying test database for alias 'default'...

 

解决:

删除polls上层目录,manager.py同文件下的__init__.py.

问题解决.

 

>python manage.py test polls
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
F
======================================================================
FAIL: test_was_published_recently_with_future_question (polls.tests.QuestionModelsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\Python\Djangostudy\mysite_project\polls\tests.py", line 17, in test_was_published_recently_with_future_question
self.assertIs(future_question.was_published_recently(),False)
AssertionError: True is not False

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)
Destroying test database for alias 'default'...

posted @ 2017-11-16 10:24  一路漂泊  阅读(3210)  评论(0编辑  收藏  举报