avast / pytest-docker

Docker-based integration tests
MIT License
406 stars 68 forks source link

`"docker-compose-v1": executable file not found in $PATH` when running from Makefile #66

Closed ciaransweet closed 2 years ago

ciaransweet commented 2 years ago

Hey folks,

I'm having a strange issue where I get:

E           Exception: Command docker-compose -f "/Users/ciaran/dev/ctk/chaostoolkit-lib/tests/test_exit/docker-compose.yaml" -p "pytest27587" up --build -d returned 1: """exec: "docker-compose-v1": executable file not found in $PATH
E           Current PATH : 
E           """.

If I run my pytest tests using pytest-docker from a Makefile target.

I'm using virtualenv for packages and I can run the tests fine like so:

(.venv) $ pytest 
# All pass fine

But if I call my Makefile target which looks like:

.PHONY: tests
tests:
    pytest
(.venv) $ make tests
# This moans about docker-compose and the $PATH

Does anyone have any ideas as to why this might be breaking?

I notice that which docker-compose gives me different outputs:

When run from outside of make:

/usr/local/bin/docker-compose

When run inside make:

/Users/ciaran/dev/ctk/chaostoolkit-lib/.venv/bin/docker-compose

I understand that in the docs you recommend installing docker-compose as a python package, but it seems like that's done regardless upon installing pytest-docker. Either way though, I'm still unsure as to why running pytest outside of make works and inside it doesn't 🙁

Any help is appreciated!

ciaransweet commented 2 years ago

Actually, it now appears that it only works if I pass the full path to the directory where the test is located.

My conftest.py looks like:

import os

import requests
from logzero import logger
from pytest import fixture

def check_slow_service() -> bool:
    try:
        resp = requests.get("http://localhost:8700")
        resp.raise_for_status()
        logger.debug("test_exit.py's slow_service is ready!")
        return True
    except Exception:
        logger.debug("test_exit.py's slow_service not yet ready, trying again.")
        return False

@fixture(scope="session")
def docker_compose_file(pytestconfig) -> str:
    return os.path.join(
        pytestconfig.rootdir, "tests", "test_exit", "docker-compose.yaml"
    )

@fixture(scope="class")
def slow_service(docker_services) -> None:
    docker_services.wait_until_responsive(
        timeout=30.0, pause=10, check=lambda: check_slow_service()
    )

The test test_exit.py lies beside conftest.py, I can only seem to run the test successfully if I pass pytest the full path to the directory containing them both...

ciaransweet commented 2 years ago

Apologies. All of this was because it turns out somewhere in our test code, someone was clearing the os environment variables... 🙃