我正在尝试使用 python manage.py test
运行测试套件,但遇到了一个错误,其结尾如下:
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: type "hstore" does not exist
LINE 1: ..., "options" varchar(255)[] NOT NULL, "conditions" hstore NOT...
此时我想进入调试器以查看完整的 sql
语句。为此,我运行了 pip install django-pdb
并将以下几行添加到我的 settings.py
中(按照 instructions ):
# Order is important and depends on your Django version.
# With Django 1.7+ put it towards the beginning, otherwise towards the end.
INSTALLED_APPS = (
...
'django_pdb',
...
)
# Make sure to add PdbMiddleware after all other middleware.
# PdbMiddleware only activates when settings.DEBUG is True.
MIDDLEWARE_CLASSES = (
...
'django_pdb.middleware.PdbMiddleware',
)
然后我尝试使用 --pm
选项重新运行测试:
python manage.py test lucy_web.tests.notifications --pm
但是,这不被识别:
manage.py test: error: unrecognized arguments: --pm
我还尝试使用 --ipdb
而不是 --pm
运行此命令,但它似乎不起作用:我只是收到一条错误消息,但没有放入调试器中。有什么想法可能是什么问题吗? test
命令是否可能不支持事后调试?
最佳答案
Django Running Test您需要启用 hstore 扩展。还运行命令
选项应该在 test
命令之后,即
python manage.py test --pm lucy_web.tests.notifications
from django.contrib.postgres.operations import HStoreExtension
class Migration(migrations.Migration):
...
operations = [
HStoreExtension(),
...
]
关于python - 在事后模式下运行 django-pdb 来执行测试命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48085313/