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 @   一路漂泊  阅读(3218)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示