Testing with sqlite the db is not clear up

Hi,

If testing using sqlite, the with setting DB_NAME. It will use same dbname after testing. Running the first time, it will not problem. But running the second time, it will show “There is 1 other sessions using the database”. So, I will need to change the DB_NAME for next test.

Is it common? or I had other setting is wrong?

Traceback (most recent call last):
  File "/project/trytond/src/abj/.tox/py3.11-sqlite/lib/python3.11/site-packages/trytond/tests/test_tryton.py", line 290, in setUpClass
    drop_db()
  File "/project/trytond/src/abj/.tox/py3.11-sqlite/lib/python3.11/site-packages/trytond/tests/test_tryton.py", line 1080, in drop_db
    database.drop(transaction.connection, name)
  File "/project/trytond/src/abj/.tox/py3.11-sqlite/lib/python3.11/site-packages/trytond/backend/postgresql/database.py", line 309, in drop
    cursor.execute(SQL("DROP DATABASE {}")
  File "/project/trytond/src/abj/.tox/py3.11-sqlite/lib/python3.11/site-packages/trytond/backend/postgresql/database.py", line 68, in execute
    cursor.execute(self, sql, args)
psycopg2.errors.ObjectInUse: database "testdb1" is being accessed by other users
DETAIL:  There is 1 other session using the database.

Are you sure you are using sqlite for testing? The traceback you pasted shows you are using a postgres database so it may be possible that there is a connection in other side that prevents its removal.

Here is my tox.ini.
Iam running with below command. the problem lies on the teardown drop db. It uses the postgres. I am using 7.0.1

tox -e “py3.11-sqlite” – -p test_module.py -f

[tox]
envlist = {py37,py38,py39,py311}-{sqlite,postgresql}

[testenv]
extras = test

commands =
    coverage run --include=./**/abj/* -m xmlrunner discover -s tests  --output-file tests/test-reports/junit.xml --locals {posargs}
commands_post =
    coverage report --include=./**/abj/* --omit=*/tests/*
    coverage xml -o tests/test-reports/coverage.xml
    genbadge tests -i tests/test-reports/junit.xml -o tests/test-reports/tests.svg
    genbadge coverage -i tests/test-reports/coverage.xml -o tests/test-reports/coverage.svg
deps =
    coverage
    unittest-xml-reporting
    psycopg2-binary >= 2.7.0
    genbadge
passenv = *
setenv =
    sqlite: TRYTOND_DATABASE_URI={env:SQLITE_URI:sqlite://}
    postgresql: TRYTOND_DATABASE_URI={env:POSTGRESQL_URI:postgresql://}
    sqlite: DB_NAME={env:SQLITE_NAME::memory:}
    postgresql: DB_NAME={env:POSTGRESQL_NAME:test}

You must have something in your environment that makes the test uses the postgresql backend instead of the sqlite.

Probably you have the TRYTOND_CONFIG environment variable pointing to a file that has the postgres backend. You must clear that environemnt variable to ensure the tests are running on sqlite

Hi @pokoli @ced ,

Oh yes the culprit is the TRYTOND_CONFIG, it trigger the postgres for this case.
Thank so much for helping.

I changed the TRYTOND_CONFIG’s uri then the testing run ok

uri = sqllite://

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.