# Testing with sqlite the db is not clear up

**URL:** https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495
**Category:** Developer
**Created:** [July 26, 2024, 12:45am UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495 "2024-07-26T00:45:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bala4901](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@bala4901](https://discuss.tryton.org/u/bala4901)
#### Post date: [July 26, 2024, 12:45am UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495/1 "2024-07-26T00:45:50Z")

</div>

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?

```auto
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.

```

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [July 26, 2024, 7:42am UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495/2 "2024-07-26T07:42:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bala4901](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@bala4901](https://discuss.tryton.org/u/bala4901)
#### Post date: [July 26, 2024, 10:24am UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495/3 "2024-07-26T10:24:13Z")

</div>

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

```auto
[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}

```

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [July 26, 2024, 10:47am UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495/4 "2024-07-26T10:47:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [July 26, 2024, 10:56am UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495/5 "2024-07-26T10:56:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bala4901](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@bala4901](https://discuss.tryton.org/u/bala4901)
#### Post date: [July 26, 2024, 11:39am UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495/6 "2024-07-26T11:39:53Z")

</div>

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://

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [July 26, 2024, 11:39pm UTC](https://discuss.tryton.org/t/testing-with-sqlite-the-db-is-not-clear-up/7495/7 "2024-07-26T23:39:57Z")

</div>

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