Bar*_*tek 5 python sqlite django unit-testing
这仅仅是一个我想根据其他人的反馈和类似的经历得出的理论.
一直在使用mySQL来运行测试,但当然内存中的SQLite数据库要快得多.但是,它似乎遇到了一些问题.
何时DATABASE_ENGINE设置为use django.db.backends.sqlite3并且我运行manage.py test,输出不符合预期:
(删除了大多数行,但指出了有趣的失败点)
$ python manage.py test
Traceback (most recent call last):
File "manage.py", line 12, in
execute_manager(settings)
File "/Users/bartekc/.virtualenvs/xx/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Users/bartekc/domains/xx/xx/associates/yy/models.py", line 51, in
class AcvTripIncentive(models.Model):
# First interesting failure
File "/Users/bartekc/domains/xx/xx/associates/yy/models.py", line 55, in AcvTripIncentive
trip = models.OneToOneField(Trip, limit_choices_to={'sites' : Site.objects.get(name='ZZ'), 'is_active' : True,})
# Next interesting failure
File "/Users/bartekc/domains/xx/xx/associates/yyz/models.py", line 252, in
current_site = Site.objects.get_current()
有这样的多个失败,但只是指出了一对.问题很明显.站点模型没有实际数据,但文件包含尝试获取站点模型下的当前或特定实例的代码.
现在,我可以想到一个简单的解决方案:OneToOneField应该切换为使用函数limit_choices_to,第二个使用相同的函数.然后在需要时调用这些函数,而不是在Django对文件进行初始扫描时调用.
但是,我的实际问题是:为什么这会发生在SQLite而不是mySQL?.两个数据库引擎通过测试有不同的方式吗?我不这么认为,因为Python正在对模型进行所有编译.
到底发生了什么?
干杯.
您是否从固定装置加载站点对象?
如果是这样,也许您偶然发现了 MySQL 和事务的一个已知问题。在此页面上搜索“MySQL and Fixtures”:http: //docs.djangoproject.com/en/dev/ref/django-admin/ ?from=olddocs
| 归档时间: |
|
| 查看次数: |
432 次 |
| 最近记录: |