avast / pytest-docker

Docker-based integration tests
MIT License
423 stars 71 forks source link

Docs for multiple docker-compose files #69

Open edinhodiluviano opened 2 years ago

edinhodiluviano commented 2 years ago

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?

Luminaar commented 2 years ago

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.

edinhodiluviano commented 2 years ago

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.

n1ngu commented 2 years ago

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?

edinhodiluviano commented 2 years ago

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