使用 django-nose 进行 Django 负载测试装置

发布于 2024-09-24 21:42:46 字数 104 浏览 1 评论 0原文

如何使用 django-nose 测试运行程序加载测试装置?

How do you load test fixtures using the django-nose test runner?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半窗疏影 2024-10-01 21:42:46
#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']
#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']
夜未央樱花落 2024-10-01 21:42:46

在您的设置方法中,只需调用:

management.call_command('loaddata', 'Category.json', verbosity=0)

然后在您的拆卸中,调用:

management.call_command('flush', verbosity=0, interactive=False)

您可以从这里导入管理:

from django.core import management

In your setup method, just call:

management.call_command('loaddata', 'Category.json', verbosity=0)

Then in your teardown, call:

management.call_command('flush', verbosity=0, interactive=False)

You can import management from here:

from django.core import management
骄傲 2024-10-01 21:42:46

只需将测试用例设为 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

Just make the test case a subclass of 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())

And then:

python manage.py test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文