Code

Opened 6 years ago

Closed 6 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:

Description

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"

runtests.py 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 runtests.py 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):

$ ./runtests.py --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/_doctest.py", 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/models.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "/home/elastic/django-dev/trunk3/tests/modeltests/basic/models.py", line ?, in modeltests.basic.models.__test__.API_TESTS
Failed example:
    Article.objects.get(pk=a.id).headline
Expected:
    u'\u6797\u539f \u3081\u3050\u307f'
Got:
    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.

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by kratorius

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

You need to specify TEST_DATABASE_CHARSET and/or TEST_DATABASE_COLLATION as described here: http://docs.djangoproject.com/en/dev/topics/testing/#the-test-database

comment:2 Changed 6 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.