3

我想在 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.json还是python3 manage.py testserver testdata会导致这个错误:

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

我能做些什么呢?

4

1 回答 1

1

python manage.py testserver [夹具名称]

例如:

python manage.py testserver SampleData

SampleData.json 文件将位于 app/fixture/

于 2016-02-01T19:59:00.290 回答