pytest-docker icon indicating copy to clipboard operation
pytest-docker copied to clipboard

Docs for multiple docker-compose files

Open edinhodiluviano opened this issue 3 years ago • 4 comments

pytest-docker already supports shared compose files. However I couldn't find it in the docs. Is it really missing? If so, can I send a PR to add something to the README?

edinhodiluviano avatar Dec 23 '21 17:12 edinhodiluviano

Hello. pytest-docker currently uses docker-compose v1. The feature you linked is available in docker-compose v2. This new version is not written in Python and so it's not possible to install it together with this library.

Support for a docker-compose v2 would require a major change to this library ― requiring users to provide their own installation of docker-compose or maybe allowing both.

I will try looking into this but please understand that it might take some time.

Luminaar avatar Jan 18 '22 20:01 Luminaar

Hum... I'm not sure how it works on the docker-compose side. But pytest-docker already supports multiple files. It is just not documented. The bellow example would work only with pytest-docker installed:

# test.py

import pytest


@pytest.fixture(scope="session")
def docker_compose_file(pytestconfig):
    return ("docker-compose-1.yml", "docker-compose-2.yml")  # here we define all compose files needed


@pytest.fixture(scope="module")
def containers(docker_services):
    docker_services.wait_until_responsive(
        timeout=30.0,
        pause=0.5,
        check=lambda: True,
    )


def test_dumb(containers):
    assert 1 == 1
# docker-compose-1.yml

version: "3"

services:
    container_1:
        image: python:3.9
        container_name: container_1
        command: ["python", "--version"]
# docker-compose-2.yml

services:
    container_2:
        image: python:3.9
        container_name: container_2
        command: ["python", "--version"]

Just run pytest test.py and for a while you will be able to see both containers running, started by pytest-docker. I was using it in a bigger project with multiple files for integration and migration tests and it was working fine.

edinhodiluviano avatar Jan 19 '22 01:01 edinhodiluviano

This new version is not written in Python and so it's not possible to install it together with this library.

Support for a docker-compose v2 would require a major change to this library ― requiring users to provide their own installation of docker-compose or maybe allowing both.

@Luminaar AFAIU, as long as the shell environment is configured in a way that the subprocess.check_output('docker-compose ...') finds the v2 installation, wouldn't everything work out of the box?

Obviously docker-compose v2 can't be installed as a python dependency anymore, but maybe this is what @edinhodiluviano is observing?

n1ngu avatar Jan 20 '22 17:01 n1ngu

I see no problem on the behavior of the library. The library already work as I need. My only concern is the documentation.

edinhodiluviano avatar Feb 07 '22 23:02 edinhodiluviano