tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.68k stars 390 forks source link

Cannot drop postgres test db #1437

Open adlmtl opened 1 year ago

adlmtl commented 1 year ago

Describe the bug finalizer() fails with

E   asyncpg.exceptions.ObjectInUseError: database "test_db" is being accessed by other users

E   DETAIL:  There is 1 other session using the database.

To Reproduce

@pytest.fixture(scope="session")
def event_loop():
    policy = asyncio.get_event_loop_policy()
    loop = policy.new_event_loop()
    yield loop
    loop.close()

@pytest.fixture(scope="session", autouse=True)
def initialize_tests(request, event_loop):
    initializer(models, db_url=test_db_url)
    request.addfinalizer(finalizer)

Expected behavior I expect the test db to be dropped as finalizer is calling connections.close_all() before trying to delete the db