문제

I'm using pgbouncer with Django. I've added test_foo database to its config to be able to run tests, because apparently Django can't use a different port for the test DB. Now the test run but at the end, when Django tries to drop the test DB, I receive

django.db.utils.DatabaseError: database "test_foo" is being accessed by other users
DETAIL:  There are 1 other session(s) using the database.

I suppose that is caused by the open connection stored by pgbouncer. What can I do?

도움이 되었습니까?

해결책

This is not the perfect solution, but it does the trick. You can force Django to use different database settings when running unit tests by adding to your settings.py:

if 'test' in sys.argv or 'test_coverage' in sys.argv:    
    # Use 5432 as db port (avoid going through pgbouncer, can't delete test DB).
    DATABASES = {
        'default': {
            'ENGINE': 'django.contrib.gis.db.backends.postgis',
            'NAME': 'xxx',
            'USER': 'xxx',
            'PASSWORD': 'xxx',
            'HOST': '',
            'PORT': '5432'
        },
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top