在post mortem模式下运行django-pdb以获取测试命令

问题描述 投票:1回答:1

我正在尝试使用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命令可能不支持事后调试吗?

python django pdb
1个回答
1
投票

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(),
        ...
    ]
© www.soinside.com 2019 - 2024. All rights reserved.