Django shell:加载测试夹具数据的命令?

Sve*_*ven 7 django shell

有没有一种简单的方法来加载夹具数据,我通常在交互式Django shell中的自动测试运行中使用?

混合使用来自数据库的模型数据和来自固定装置的其他模型数据可能很尴尬.在我的情况下,我有一些只读表和魔杖来试验我之后可以丢弃的一些数据.

我可以加载像这里描述的夹具文件,但重复使用有点麻烦......

old*_*sea 6

ilardm的答案指向了正确的方向,特别是你想要的是:

from django.core.management import call_command
call_command('loaddata', 'fixture_name.json')
Run Code Online (Sandbox Code Playgroud)

编辑:但是在测试用例中包含fixture的正确方法是这样的:

class TestThis(TestCase):
    fixtures = ['myfixture.json']

    def setUp(self):
        # Ready to test
Run Code Online (Sandbox Code Playgroud)


Dan*_*man 5

我期待的./manage.py loaddata fixture_name.json是你想要的。