I have a django 1.4 project using mysql as the backend. I have the tests setup to run in memory
if 'test' in sys.argv:
DATABASES['default'] = {'ENGINE': 'django.db.backends.sqlite3'}
The issue is I need to use mysql functionality (full text indexes).
Is there a way to have django run MySQL in memory for testing?
My project relies on fulltext indexes. When the project is being developed on I syncdb then execute a .sql
file with the sql to create the full text indexes.
I would like to use django orm full text searching in the functions I test. I am trying to manually add the fulltext index on each tests' initialization like:
cursor.execute('alter table mytable add fulltext(one, two)')
This does not work when using sqlite (I believe because sqlite does not support Fulltext indexing)
The above sql DOES work when I remove the in memory tests. I like the speed of in memory tests. Is there a way I can run mysql in memory?
How do people test apps that rely on database specific features? like full text indexing or gis, etc... Do they have to run the tests normally on the filesystem?
Thank you
MySQL has a MEMORY
storage engine. You can activate it using the OPTIONS
key:
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'localhost',
'NAME': 'foo',
'USER': 'bar',
'PASSWORD': 'baz',
'OPTIONS': {
'init_command': 'SET storage_engine=MEMORY'
}
}
}
BUT according to the documentation:
MEMORY tables cannot contain BLOB or TEXT columns.
Therefore i suppose it's pretty useless for your (and many other) use cases.
I found a few other tips for speeding up MySQL tests in this thread. Make sure to read Daniel Roseman's answer about using the INNODB
engine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With