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:Python27libunittestloader.py", line 254, in _find_tests
module = self._get_module_from_name(name)
File "C:Python27libunittestloader.py", line 232, in _get_module_from_name
__import__(name)
File "D:PythonDjangostudymysite_projectpolls ests.py", line 8, in <module>
from .models import Question
File "D:PythonDjangostudymysite_projectpollsmodels.py", line 14, in <module>
class Question(models.Model):
File "C:Python27libsite-packagesdjangodbmodelsase.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:PythonDjangostudymysite_projectpolls ests.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'...

原文地址:https://www.cnblogs.com/ylpb/p/7843010.html