I am using Robot Framework for my acceptance testing.
To start the django server I run the python manage.py runserver
command from the RobotFramework. After that, I call python manage.py migrate
. But the tests are slow because is not using an in-memory database.
I tried creating a new setting file called testing and I an using the following configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
and setting the enviroment variable DJANGO_SETTINGS_MODULE at runtime with this config.
I run a migrate followed by a runserver but the database does not exist. I can't figure out why. If I use a physical database it works.
I tried to check how the Django TestCase works to run and create the database but I could not find it.
I try to simulate make migrate
before running test cases by calling execute_from_command_line()
manually.
So the command I choose is: (removing poetry run
if you don't use poetry).
poetry run ./manage.py test --settings=myproject.settings_test
I put this command into GNUMakefile
to allow me use make test
.
Then inside myproject/settings_test.py
:
from .settings import *
ALLOWED_HOSTS = [ '127.0.0.1', ]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
from django.core.management import execute_from_command_line
execute_from_command_line(['./manage.py', 'migrate'])
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