I use django==3.1.2
and selenium and selenium==3.141.0
.
I have a test file with 12 tests and when I execute them like so:
python3 manage.py test myapp.tests --settings=app.settings_test
2 of the tests fail. When I execute them singly like so
python3 manage.py test myapp.tests.MyTests.test_this --settings=app.settings_test
they don't fail.
The errors are usually something like django.db.utils.OperationalError: database table is locked: visitors_person
The above exception was the direct cause of the following exception: myapp_cars
...
django.core.management.base.CommandError: Database file:memorydb_default?mode=memory&cache=shared couldn't be flushed. Possible reasons: * The database isn't running or isn't configured correctly. * At least one of the expected database tables doesn't exist. * The SQL was invalid. Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.
or
django.db.utils.OperationalError: database table is locked: myapp_drivers
It always errors on different models of the database.
My database in settings_test.py
looks like this:
DATABASES['default'] = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(tempfile.gettempdir(), 'db_test.sqlite3'),
'OPTIONS': {
'timeout': 20,
}
}
During these tests I create about 120 entries spread over 12 tests, the fixtures install about 20 entries. So not that much. After googling the error I added the timeout and I added time.sleep(1)
after each MyModal.objects.create()
to see if this is the reason, but it doesn't help.
Any ideas?