dimanche 20 décembre 2020

Operational Error while running unit tests Django

I have dockerized my Django app together with my postgres Database. However after the dockerization, the unit tests that i have written (not the SimpleTestCase but the TestCase ones) stopped running.

I thought it could be because of the new db so I modifies the setting for the tests to run with the default DJango db:

import sys

if 'test' in sys.argv:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': BASE_DIR / 'db.sqlite3'
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'postgres',
            'USER': 'postgres',
            'PASSWORD': 'postgres',
            'HOST': 'db',
            'PORT': 5432,
        }
    }

Still, I get the following error:

Creating test database for alias 'default'...
Traceback (most recent call last):
  File ".../.local/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File ".../.local/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: near "[1]": syntax error

Any ideas what might be the problem and how it can be fixed?

Aucun commentaire:

Enregistrer un commentaire