我想在 Django 中启动一个测试服务器,以便我能够通过 Jasmine/FrisbyJs 测试我的 API。
为此,我发现 python3 manage.py testserver
会创建一个测试数据库并加载 fixture 中提供的所有测试数据,这听起来正是我所需要的。我没有运行 Django-Testcases ATM。
我创建了一个名为 testdata.json 的夹具并将其存储在 ./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.
我该怎么办?
最佳答案
python manage.py testserver [夹具名称]
例如:
python manage.py testserver SampleData
SampleData.json 文件将在 app/fixture/
关于python - 未使用 Django Testserver 固定装置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30275650/