gpt4 book ai didi

python - 加载夹具时 Django 单元测试出错

转载 作者:太空狗 更新时间:2023-10-30 02:00:24 24 4
gpt4 key购买 nike

我正在为 Django 应用程序进行单元测试。我的测试需要数据库中的一些数据,所以我使用的是 json fixture。

我有两个固定装置:

  1. 对于用户来说,它工作正常。
  2. 对于一些网页

夹具 2 导致以下错误:

Problem installing fixture 'C:\Users\luc\Dev\Hg\mnl-adminpub\website\fixtures\website-unittest.json': Traceback (most recent call last):
File "C:\Python26\lib\site-packages\django\core\management\commands\loaddata.py", line 169, in handle
obj.save(using=using)
File "C:\Python26\lib\site-packages\django\core\serializers\base.py", line 165, in save
models.Model.save_base(self.object, using=using, raw=True)
File "C:\Python26\lib\site-packages\django\db\models\base.py", line 528, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "C:\Python26\lib\site-packages\django\db\models\manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "C:\Python26\lib\site-packages\django\db\models\query.py", line 1479, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 783, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 727, in execute_sql
cursor.execute(sql, params)
File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 86, in execute
return self.cursor.execute(query, args)
File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 173, in execute
self.errorhandler(self, exc, value)
File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1366, "Incorrect string value: '\\xE2\\x80\\xA8<br...' for column 'html' at row 1")

我已经使用 dumpdata 创建了夹具。我已经用 loaddata 测试了它,它工作正常。我正在使用 mysql。

知道问题的可能原因吗?

谢谢你的帮助

最佳答案

你应该使用 TEST_CHARSET ,但 数据库配置中。像那样:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_sbet',
'USER': 'test_sbet',
'TEST_CHARSET': 'UTF8',
}
}

关于python - 加载夹具时 Django 单元测试出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3819693/

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