django - initial_data.json 在测试前未加载

标签 django testing nose

我正在使用 django_nose 来运行我的测试。我有一个夹具 initial_data.json,它是一个应用程序的文件夹:my_app/fixtures/initial.json

使用 python manage.py syncdb 时夹具加载正常,但在运行测试 python manage.py test my_app 时根本不加载(虽然我猜它应该加载!?)。任何可能出错的指针?

最佳答案

我引用 official documentation :

Once you've created a fixture and placed it in a fixtures directory in one of your INSTALLED_APPS, you can use it in your unit tests by specifying a fixtures class attribute on your django.test.TestCase subclass:

from django.test import TestCase
from myapp.models import Animal

class AnimalTestCase(TestCase):
    fixtures = ['mammals.json', 'birds']

    def setUp(self):
        # Test definitions as before.
        call_setup_methods()

    def testFluffyAnimals(self):
        # A test that uses the fixtures.
        call_some_test_code()

关于django - initial_data.json 在测试前未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12495419/

相关文章:

django - 如何修复 django dumpdata "_django_curs_139705..."的错误

django - 在一个用于CI(Bamboo)的容器中运行postgres 9.5和django

Django ModelForm 验证失败且没有错误

windows - 单个 .msi Windows 程序包安装程序文件的最大大小是多少?

python - 循环 : 1 test per iteration 中的 assertRaises

python - 如何将 cProfile 与 nosetest --with-profile 一起使用?

mysql - 如何在 celery 任务中强制 db 提交 django-orm 中的单个保存

C++ GoogleTest - 静态成员和链接器错误 LNK 2001

testing - 如何测试 RTMP 流负载测试

python - 如何构建相互构建的 Nose 单元测试?