Creates a MySQL cursor before each test to avoid the extra SET SQL_AUTO_IS_NULL = 0 request.

This commit is contained in:
Bertrand Bordage 2015-06-17 23:00:52 +02:00
parent d9e19a8ca5
commit d2b03e5d8d
4 changed files with 25 additions and 0 deletions

View file

@ -6,6 +6,7 @@ try:
except ImportError: # For Python 2.6
from unittest2 import skipIf
from django import VERSION as django_version
from django.conf import settings
from django.core.cache import DEFAULT_CACHE_ALIAS
from django.db import connection
@ -16,6 +17,12 @@ from .models import Test
class SettingsTestCase(TransactionTestCase):
def setUp(self):
if django_version >= (1, 7) and connection.vendor == 'mysql':
# We need to reopen the connection or Django
# will execute an extra SQL request below.
connection.cursor()
@override_settings(CACHALOT_ENABLED=False)
def test_decorator(self):
with self.assertNumQueries(1):

View file

@ -3,6 +3,7 @@
from __future__ import unicode_literals
from threading import Thread
from django import VERSION as django_version
from django.db import connection, transaction
from django.test import TransactionTestCase, skipUnlessDBFeature
@ -22,6 +23,12 @@ class TestThread(Thread):
@skipUnlessDBFeature('test_db_allows_multiple_connections')
class ThreadSafetyTestCase(TransactionTestCase):
def setUp(self):
if django_version >= (1, 7) and connection.vendor == 'mysql':
# We need to reopen the connection or Django
# will execute an extra SQL request below.
connection.cursor()
def test_concurrent_caching(self):
t1 = TestThread().start_and_join()
t = Test.objects.create(name='test')

View file

@ -2,6 +2,7 @@
from __future__ import unicode_literals
from django import VERSION as django_version
from django.contrib.auth.models import User
from django.db import connection, transaction
from django.test import TransactionTestCase
@ -10,6 +11,12 @@ from .models import Test
class AtomicTestCase(TransactionTestCase):
def setUp(self):
if django_version >= (1, 7) and connection.vendor == 'mysql':
# We need to reopen the connection or Django
# will execute an extra SQL request below.
connection.cursor()
def test_successful_read_atomic(self):
is_sqlite = connection.vendor == 'sqlite'

View file

@ -25,6 +25,10 @@ class WriteTestCase(TransactionTestCase):
def setUp(self):
self.is_sqlite = connection.vendor == 'sqlite'
if django_version >= (1, 7) and connection.vendor == 'mysql':
# We need to reopen the connection or Django
# will execute an extra SQL request below.
connection.cursor()
def test_create(self):
with self.assertNumQueries(1):