运行 django-pdb 在 post 测试命令的 mortem 模式

Running django-pdb in post mortem mode for a test command

我正在尝试 运行 使用 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 命令可能不支持 post 实时调试吗?

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(),
        ...
    ]