我正在为现有的django项目编写一些单元测试,该项目到目前为止还没有进行单元测试。
当我使用
从命令行运行测试时 ./manage.py test
我得到了
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named hijack
现在实际安装了hijack,因为我可以在使用
运行服务器时从浏览器中使用它./manage.py runserver
manage.py的内容是
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mtmdjango.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
那么......在运行测试时如何禁用劫持的引用,或者如何在运行测试时在命令行下启用劫持?
(有人可以创建并添加标签django-hijack)
答案 0 :(得分:0)
我在
处完成了教程https://docs.djangoproject.com/en/1.10/intro/tutorial01/到https://docs.djangoproject.com/en/1.10/intro/tutorial05/
原来我的命令行错了。
python manage.py test contacts
给了我期待的输出。