【问题标题】:Django Testserver fixtures not used未使用 Django Testserver 固定装置
【发布时间】:2015-07-28 07:57:03
【问题描述】:

我想在 Django 中启动一个测试服务器,以便能够通过 Jasmine/FrisbyJs 测试我的 API。

为此,我发现python3 manage.py testserver 会创建一个测试数据库并加载夹具中提供的所有测试数据,这听起来正是我所需要的。我没有运行 Django-Testcases ATM。

我创建了一个名为 testdata.json 的 Fixture 并将其存储在 ./fixtures 中。 我也这样设置了我的./projname/settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Fixture Dir
FIXTURE_DIRS = (
    os.path.join(BASE_DIR, 'fixtures'),
)

我还确保 python3 manage.py loaddata testdata 可以正常工作:

Installed 1 object(s) from 1 fixture(s)

但是,运行 python3 manage.py testserver testdata.jsonpython3 manage.py testserver testdata 会导致此错误:

CommandError: Error: No database fixture specified. Please provide the path of at least one fixture in the command line.

对此我能做些什么?

【问题讨论】:

    标签: python django django-admin django-fixtures


    【解决方案1】:

    python manage.py testserver [夹具名称]

    例如:

    python manage.py testserver SampleData
    

    SampleData.json 文件将在 app/fixture/ 中

    【讨论】:

      猜你喜欢
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      相关资源
      最近更新 更多