0

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?

Deepak Rai
  • 2,163
  • 3
  • 21
  • 36
Tom
  • 2,545
  • 5
  • 31
  • 71
  • Dup of [OperationalError: database is locked](https://stackoverflow.com/questions/3172929/operationalerror-database-is-locked) – JPG Jan 29 '21 at 18:28
  • not really, I already tried the solution from this post, such as adding a timer AND I think sqllite can handle 120 entries no? – Tom Jan 29 '21 at 18:32
  • Have you tried any other DBs other than SQLite, as mentioned in the post? – JPG Jan 29 '21 at 18:33
  • true, I have not, kk I'll remove it – Tom Jan 29 '21 at 18:34

0 Answers0