Search code examples
pythondjangounit-testingdjango-testingdjango-tests

Django: How to run tests against empty (non populated) database


By running './manage.py test', data from local 'postgres' database are populated into 'test_postgres' database. I am not able to find way, how to disable this behavior. By running './manage.py test', I want to get non populated database with applied migrations.

class Local(Common):
    DEBUG = True

    # Testing
    INSTALLED_APPS = Common.INSTALLED_APPS
    INSTALLED_APPS += ('django_nose',)
    TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
    NOSE_ARGS = [
        BASE_DIR,
        '-s',
        '--nologcapture',
        '--with-coverage',
        '--with-progressive'
    ]
    # Postgres
    DATABASES = {
        'default': dj_database_url.config(
            default='postgres://postgres:@postgres:5432/postgres',
            conn_max_age=int(os.getenv('POSTGRES_CONN_MAX_AGE', 600)),
        )
    }

Solution

  • By running './manage.py test', data from local 'postgres' database are populated into 'test_postgres' database.

    No it isn't. Django will create a new empty database for each test.