Test Utilities

The following can be imported from django_mysql.test.utils.

override_mysql_variables(using='default', **options)[source]

Overrides MySQL system variables for a test method or for every test method in a class, similar to Django’s override_settings. This can be useful when you’re testing code that must run under multiple MySQL environments (like most of django-mysql). For example:

class MyTests(TestCase):

    def test_it_works_in_mssql(self):

    def test_it_works_in_ansi_mode(self):

During the first test, the SQL_MODE will be MSSQL, and during the second, it will be ANSI; each slightly changes the allowed SQL syntax, meaning they are useful to test.


This only sets the system variables for the session, so if the tested code closes and re-opens the database connection the change will be reset.


The connection alias to set the system variables for, defaults to ‘default’.