Django 做单元测试时报错了
IDE用eclipse + PyDev, Django的项目,用apache2启动,有一个test.py。
Django 版本1.6 Python版本2.7.6
settings中UNIT_TEST_FLAG已经设置为True
当我用eclipse的Debug As Python unit-test做单元测试时,出现了下面的错误...
pydev debugger: starting (pid: 23225) Finding files... done. Importing test modules ... 172.17.0.2:6379 {'default': {'ENGINE': 'django.db.backends.mysql', 'NAME': 'mydatabase', 'OPTIONS': {'charset': 'utf8mb4'}, 'HOST': '172.17.0.1', 'USER': 'root', 'PASSWORD': 'hello123', 'PORT': '3306'}, 'OPTIONS': {'autocommit': True, 'timeout': 20}} done. Traceback (most recent call last): File "/home/jeff/software/eclipse/plugins/org.python.pydev_4.0.0.201504132356/pysrc/pydevd.py", line 2278, in <module> globals = debugger.run(setup['file'], None, None) File "/home/jeff/software/eclipse/plugins/org.python.pydev_4.0.0.201504132356/pysrc/pydevd.py", line 1704, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/home/jeff/software/eclipse/plugins/org.python.pydev_4.0.0.201504132356/pysrc/runfiles.py", line 234, in <module> main() File "/home/jeff/software/eclipse/plugins/org.python.pydev_4.0.0.201504132356/pysrc/runfiles.py", line 78, in main return pydev_runfiles.main(configuration) # Note: still doesn't return a proper value. File "/home/jeff/software/eclipse/plugins/org.python.pydev_4.0.0.201504132356/pysrc/pydev_runfiles.py", line 835, in main PydevTestRunner(configuration).run_tests() File "/home/jeff/software/eclipse/plugins/org.python.pydev_4.0.0.201504132356/pysrc/pydev_runfiles.py", line 793, in run_tests MyDjangoTestSuiteRunner(run_tests).run_tests([]) File "/home/jeff/software/eclipse/plugins/org.python.pydev_4.0.0.201504132356/pysrc/pydev_runfiles.py", line 813, in run_tests raise AssertionError("Unable to run suite with DjangoTestSuiteRunner because it couldn't be imported.") AssertionError: Unable to run suite with DjangoTestSuiteRunner because it couldn't be imported.
DjangoTestSuiteRunner 好像是一个旧的Test Runner,1.6及1.6之后好像是基于unittest的,我的测试代码也是导入unittest的,我该怎么切换到unittest?
Python的新手,要接受一个准备上线的项目维护,求教,谢谢!如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
顶一下
但我好像没有看到有DjangoTestSuiteRunner的包啊?
需要在settings中的INSTALLED_APPS 导入django.test.simple.DjangoTestSuiteRunner吗?
包没有引入 可以去到最后一行的文件里看看都需要引入哪些包
需要在settings中的INSTALLED_APPS 导入django.test.simple.DjangoTestSuiteRunner吗?我在单元测试的文件import了也不行,在INSTALLED_APPS 中添加了也不行
AssertionError: Unable to run suite with DjangoTestSuiteRunner because it couldn't be imported.