Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

383
Visualizações
Django parallel testing: Test processes incorrectly accessing test databases

I have a Django 3.0.8 project running locally, connected to a local PostgreSQL database (postgres:///myapp). When I run python manage.py test, my unit tests run fine; a test database called test_myapp automatically gets created, and it's correctly accessed.

However, when I run python manage.py test --parallel 8, the test fails. I see that 8 cloned databases are correctly generated (test_myapp_1, test_myapp_2,..., test_myapp_8), but I get errors like these:

psycopg2.OperationalError: FATAL:  database "myapp_3" does not exist

It appears that for parallel tests, databases are accessed incorrectly (trying to access the database myapp_N rather than test_myapp_N). I'm trying to figure out if my local config has issues, but this is all I have in my base config:

DATABASES = {
    'default': env.db('DATABASE_URL', default='postgres:///myapp'),
}
DATABASES['default']['ATOMIC_REQUESTS'] = True

Why are my parallel tests processes not accessing their respective cloned test databases correctly?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

A simple solution that worked for me is to explicitly specify the test database name in settings.py, e.g.,

DATABASES = {
    'default': {
        ...
        'TEST': {
            # Avoid naming it the same as your original database name. 
            # Otherwise, it will be used while testing (and even may get deleted).
            'NAME': 'name_of_your_choice',
        },
    },
    ...
}

If you are using multiple databases, you may need to do it for all of them.

over 4 years ago · Santiago Trujillo Relatório

0

for using the PostgreSQL database on your Django project you can configure your database the same.

DATABASES = {
    'default': {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": 'Table_name',
        "USER": 'user_name',
        "PASSWORD": 'password',
        "HOST": 'localhost', # or 127.0.0.1
        "PORT": '5432', #5432 is the default PostgreSQL port if you change it must change this port
    }
}

and for setting multiple databases on your Django project, you can see this page and use it.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda