你如何使用django-nose测试运行器加载测试夹具?
问问题
2602 次
3 回答
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']
于 2010-09-24T08:33:30.743 回答
2
在您的设置方法中,只需调用:
management.call_command('loaddata', 'Category.json', verbosity=0)
然后在你的拆解中,调用:
management.call_command('flush', verbosity=0, interactive=False)
您可以从这里导入管理:
from django.core import management
于 2012-03-22T05:13:33.603 回答
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
于 2012-08-22T00:29:32.603 回答