我正在使用 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/