在django单元测试中加载固定装置 [英] Loading fixtures in django unit tests

查看:107
本文介绍了在django单元测试中加载固定装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开始为django编写单元测试,我有一些关于灯具的问题:



我制作了整个项目db(不是某些应用程序),我想为每个测试加载它,因为它似乎只加载某些应用程序的夹具是不够的。



我想将夹具存储在/proj_folder/fixtures/proj_fixture.json中。



我设置了 FIXTURE_DIRS =('/ fixtures /',) 在我的settings.py中。
然后在我的测试用例中我正在尝试

  fixtures = ['proj_fixture.json'] 

但我的装置不加载。
如何解决?
如何添加搜索装置的位置?
一般来说,是否可以为每个应用程序中的每个测试加载整个test_db的灯具(如果它相当小的话)?
谢谢!

解决方案

你真的有一个文件夹 / fixtures /



您可能打算使用:

  FIXTURE_DIRS =('/ path / to / proj_folder / fixtures /',)


I'm trying to start writing unit tests for django and I'm having some questions about fixtures:

I made a fixture of my whole project db (not certain application) and I want to load it for each test, because it looks like loading only the fixture for certain app won't be enough.

I'd like to have the fixture stored in /proj_folder/fixtures/proj_fixture.json.

I've set the FIXTURE_DIRS = ('/fixtures/',) in my settings.py. Then in my testcase I'm trying

fixtures = ['proj_fixture.json']

but my fixtures don't load. How can this be solved? How to add the place for searching fixtures? In general, is it ok to load the fixture for the whole test_db for each test in each app (if it's quite small)? Thanks!

解决方案

Do you really have a folder /fixtures/ on your hard disk?

You probably intended to use:

FIXTURE_DIRS = ('/path/to/proj_folder/fixtures/',)

这篇关于在django单元测试中加载固定装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆