如何使用django-nose测试运行器加载测试夹具?
答案 0 :(得分:4)
#settings.test.py
INSTALLED_APPS += ('django_nose', )
TEST_RUNNER = 'django_nose.run_tests'
#appname/tests.py
from datetime import date,datetime, timedelta
from django.contrib.auth.models import User
from django.test.client import Client
from django.test import TestCase
class BetViewsTestCase(TestCase):
#files placed in appname/fixtures/restaurant.json, appname/fixtures/map.json
fixtures = ['authtestdata.json', 'restaurant.json', 'map.json']
答案 1 :(得分:2)
在您的设置方法中,只需致电:
management.call_command('loaddata', 'Category.json', verbosity=0)
然后在你的拆解中,请致电:
management.call_command('flush', verbosity=0, interactive=False)
您可以从此处导入管理:
from django.core import management
答案 2 :(得分:2)
只需将测试用例设为FastFixtureTestCase的子类。
from django_nose import FastFixtureTestCase
from myapp.models import MyModel
from nose_tools import eq_
class TestFixtureLoading(FastFixtureTestCase):
fixtures = ['mymodel_data.yaml']
def test_fixture_loading(self):
eq_(1, MyModel.objects.count())
然后:
python manage.py test