Django Pytests in docker container not using temp sqlite3 database
I'm running pytest on a django app that lives in a docker container. Pytest is being run in the docker container after it's built. Normally the django app references a mysql container running on the same host. I've been trying to use a sqlite3 db instead for testing, but I've been having trouble getting it to use this instead of the mysql container.
I've gotten it to work one way: test_settings.py:
from .settings import *
# Override the DATABASES setting to use SQLite for tests
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
pyproject.toml:
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = [
"--ds=django_app.test_settings",
]
[tool.pytest.ini_options.env]
PYTHONPATH = "web"
I don't want to do it this way because of the wildcard import (also my ruff linter doesn't like).
I've tried to overwrite using conftest.py, but it seems to get overwritten again by the DJANGO_SETTINGS_MODULE env variable, which is set in the container's env file.
How can I get my pytest to use sqlite3 without using this wildcard import on test_settings.py? Or without using test_settings.py at all?
Thanks