#16885 closed Bug (fixed)
django.test.testcases.connections_support_transactions always returns False if TEST_MIRROR is used
Reported by: | grimfandjango | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | m.vantellingen@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If a project is set up with multiple databases, and at least one of the databases uses the TEST_MIRROR option, django.test.testcases.connections_support_transactions will always return False, forcing any tests inheriting from TestCase into the (substantially slower) TransactionTestCase mode.
Example: take the test case:
class TestTest(TestCase): def test_connections_support_transactions(self): import django.test.testcases self.assertTrue(django.test.testcases.connections_support_transactions())
and the database setup:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': '/tmp/foo.db', # Or path to database file if using sqlite3. } }
Test output:
Creating test database for alias 'default'... . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK
Switch to:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': '/tmp/foo.db', # Or path to database file if using sqlite3. }, 'reporting': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': '/tmp/foo2.db', 'TEST_MIRROR': 'default', } }
Test output:
FAIL: test_connections_support_transactions (foo.testit.tests.TestTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/../venvs/django_svn/foo/../foo/testit/tests.py", line 15, in test_connections_support_transactions self.assertTrue(django.test.testcases.connections_support_transactions()) AssertionError: False is not True
The same problem occurs with the MySQL backend if configured analogously.
The underlying issue is that in conn.features.supports_transactions for conn in connections.all() in connections_support_transactions, conn.features.supports_transactions is None for the alias.
Attachments (1)
Change History (7)
comment:1 by , 13 years ago
Cc: | added |
---|
comment:2 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 13 years ago
Not really sure about the unittest since there is no easy way to override the call_command() function call. Would be nice to get this in before 1.4.
comment:4 by , 13 years ago
Has patch: | set |
---|
When
TEST_MIRROR
is set:BaseDatabaseCreation.create_test_db
is never called for the slave,BaseDatabaseFeatures.confirm
isn't called either,connections['slave'].features.supports_transactions
isn't computed, hence the problem.I see two ways to fix this: call
confirm
for the slave, or copy the features from the master to the slave after the master database is created.