S
S
Sergey Alekseev2019-01-26 11:55:55
Django
Sergey Alekseev, 2019-01-26 11:55:55

Python/Django/Docker/Docker-Compose, why can't I hook into a container from pytest?

There is a project on Django.
There are also postgres, redis, web (application) containers.
When I start the application, I normally connect to the container with the base, but I can’t from pytesta, swears at the unknown service "postgres"
pytest.ini

[pytest]
addopts = --reuse-db --no-migrations
DJANGO_SETTINGS_MODULE = core.settings
python_files = tests.py test_*.py *_tests.py

I use local_settings as settings, local settings are imported at the end of the settings file, if any.
local_settings
from .settings import *

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'provizorro',
        'USER': 'provizorro',
        'PASSWORD': 'Provizorro666',
        'HOST': 'postgres',
        'PORT': 5432,
    }
}

DEBUG = True

CELERY_BROKER_URL = 'redis://127.0.0.1:6001'
CELERY_BROKER_BACKEND = "redis"
CELERY_REDIS_PORT = 6001
CELERY_REDIS_HOST = "localhost"
CELERY_RESULT_BACKEND = 'redis://'

And docker-compose
version: '3'

services:
 postgres:
   image: postgres
   ports:
     - "5001:5432"
   environment:
     POSTGRES_DB: provizorro
     POSTGRES_USER: provizorro
     POSTGRES_PASSWORD: Provizorro666
   volumes:
     - /home/sergey/Projects/data-pg:/var/lib/postgresql/data
 redis:
   image: redis
   ports:
     - "6001:6379"
 web:
   restart: always
   build: .
   command: bash -c "python3.6 src/manage.py runserver 0.0.0.0:8000"
   ports:
     - "8000:8000"
   volumes:
     - .:/code
   depends_on:
     - postgres
     - redis

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Bogoyavlensky, 2019-02-14
@abogoyavlensky

You may need to wait for the container with the database to start using the wait-for-it script : https://docs.docker.com/compose/startup-order/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question