Opened 10 years ago

Closed 10 years ago

#8780 closed (invalid)

Various unicode unit tests may fail on MySQL, since test database may be created without utf-8 character set

Reported by: Richard Davies <richard.davies@…> Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords:
Cc: richard.davies@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The MySQL installation notes state that the database character set should be utf-8, specified by either "CREATE DATABASE <dbname> CHARACTER SET utf8;" or a database-wide default "mysqld -C utf8" or "default-character-set = utf8" creates a new test database, but does not force the character set to utf8 when it does so.

This means that users configured with a database-wide default of utf8 will find that works fine.

However, users who only set this for their working Django database, may find that the new test database has the wrong character set, in which case they will see several tests fail (one example below):

$ ./ --settings=SETT_mysql basic
FAIL: Doctest: modeltests.basic.models.__test__.API_TESTS
Traceback (most recent call last):
  File "/home/elastic/django-dev/trunk3/django/test/", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for modeltests.basic.models.__test__.API_TESTS
  File "/home/elastic/django-dev/trunk3/tests/modeltests/basic/", line unknown line number, in API_TESTS

File "/home/elastic/django-dev/trunk3/tests/modeltests/basic/", line ?, in modeltests.basic.models.__test__.API_TESTS
Failed example:
    u'\u6797\u539f \u3081\u3050\u307f'
    u'?? ???'

Ran 1 test in 0.149s

FAILED (failures=1)

The answer is probably for the test framework to force a complete "CREATE DATABASE <dbname> CHARACTER SET utf8;" when it creates the test database when run with the mysql backend.

Change History (2)

comment:1 Changed 10 years ago by Ivan Giuliani

You need to specify TEST_DATABASE_CHARSET and/or TEST_DATABASE_COLLATION as described here:

comment:2 Changed 10 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

This is documented and expected. We don't/can't make too many assumptions about the target environment, so we provide a setting if changes are required. The same test framework is used for testing non-core stuff, so we can't mess with the character encoding too much, since people should be testing their apps with the same encoding and collation as in their production settings.

Note: See TracTickets for help on using tickets.
Back to Top