gpt4 book ai didi

django 装置 : Where to add a fixture file

转载 作者:行者123 更新时间:2023-11-28 19:53:51 30 4
gpt4 key购买 nike

我正在尝试创建一组测试用例来覆盖我的 Django 应用程序。我需要预定义的数据库数据来运行我的一些测试。所以我决定使用固定装置。

我所做的是:1)创建 fixture 文件: oleg$ python manage.py dumpdata goserver > fixture1.json2)将fixture放置在应用程序所在的目录中 oleg$ cp fixture1.json goserver/3) 在我的应用程序的测试文件中写下纹理名称

   class GoserverTestCase(TestCase):
fixtures = ['fixture1.json']

def setUp(self):
pass

def testUserIsAdded(self):
print "Users" , User.objects.all()
#print ActiveList.objects.all()
self.assertEquals(True, True)

4) 使用命令运行文本案例:oleg$ python manage.py test --verbosity=2 goserver

测试运行的输出为(部分):

Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures'. Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures' for json fixture 'initial_data'... No json fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures'. Checking '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures' for fixtures... Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures'. Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures' for json fixture 'initial_data'... No json fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures'. Checking '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures' for fixtures... Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures'. Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures' for json fixture 'initial_data'... No json fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures'. Checking '/' for fixtures... Trying '/' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/'. Trying '/' for json fixture 'initial_data'... No json fixture 'initial_data' in '/'. Checking 'U' for fixtures... Trying 'U' for xml fixture 'initial_data'... No xml fixture 'initial_data' in 'U'. Trying 'U' for json fixture 'initial_data'... No json fixture 'initial_data' in 'U'. Checking 's' for fixtures... Trying 's' for xml fixture 'initial_data'... No xml fixture 'initial_data' in 's'. Trying 's' for json fixture 'initial_data'..

实际上问题是根本没有找到fixture,所以没有添加我想添加到测试数据库中的数据。你能给我一个解决问题的方法吗

我尝试了一种新的方法。我刚刚转储了完整的数据库并将其放入应用程序文件夹。

但我遇到了一些编码问题。

能否请您检查错误响应:

文件“build/bdist.macosx-10.3-i386/egg/MySQLdb/cursors.py”,第 168 行,在执行中 如果不是 self._defer_warnings: self._warning_check() 文件“build/bdist.macosx-10.3-i386/egg/MySQLdb/cursors.py”,第 82 行,在 _warning_check 警告(w[-1], self.Warning, 3) 文件“/opt/local/lib/python2.5/warnings.py”,第 62 行,警告 全局变量) 文件“/opt/local/lib/python2.5/warnings.py”,第 102 行,warn_explicit 提出消息警告:不正确的字符串值:第 1 行的“object_repr”列的“\xD0\x9D\xD0\xB0\xD0...”

testUserIsAdded (jin.goserver.tests.GoserverTestCase) ... 用户 []

还有一个问题。当我禁用固定装置时,我仍然收到错误消息:

单元测试代码覆盖率结果

追溯(最近的调用最后): 文件“manage.py”,第 11 行,位于 执行经理(设置) 文件“/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/init.py”,第 340 行,在执行管理器中 实用程序.execute() 文件“/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/init.py”,第 295 行,在执行 self.fetch_command(子命令).run_from_argv(self.argv) 文件“/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/base.py”,第 192 行,在 run_from_argv self.execute(*args, **options.dict) 文件“/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/base.py”,第219行,执行 输出 = self.handle(*args, **options) 文件“/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/commands/test.py”,第 33 行,句柄 failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive) 文件“/opt/local/lib/python2.5/site-packages/django_test_coverage-0.1-py2.5.egg/django-test-coverage/runner.py”,第 58 行,在 run_tests modules.extend(_package_modules(*pkg)) 文件“/opt/local/lib/python2.5/site-packages/django_test_coverage-0.1-py2.5.egg/django-test-coverage/runner.py”,第 92 行,在 _package_modules modules.append(import(impstr + '.' + name, {}, {}, [''])) 文件“/Users/oleg/jin/goclub/trunk/jin/goserver/admin.py”,第 11 行,在 admin.site.register(ActiveList,ActiveListAdmin) 文件“/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/contrib/admin/sites.py”,第 64 行,在寄存器中 raise AlreadyRegistered('模型 %s 已经注册' % model.name)django.contrib.admin.sites.AlreadyRegistered:模型ActiveList已经注册

最佳答案

对于第一个问题,将 fixture 文件放在哪里:在每个应用程序中创建一个名为 fixtures 的文件夹,并将您的 fixture 数据放在那里。

关于关于完整性错误的第二个问题,请查看关于内容类型和固定装置问题的讨论:

Problems with contenttypes when loading a fixture in Django

关于django 装置 : Where to add a fixture file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1385724/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com