Skip to content

Commit

Permalink
Merge pull request #2349 from pini-gh/pini-support-docker-compose-v1
Browse files Browse the repository at this point in the history
Tests: support custom 'docker compose' command
  • Loading branch information
buchdag committed Dec 20, 2023
2 parents a8478d1 + 9e77e81 commit 4f85eef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ need more verbosity ?

pytest -s

Note: By default this test suite relies on Docker Compose v2 with the command `docker compose`. It still supports Docker Compose v1 via the `DOCKER_COMPOSE` environment variable:

DOCKER_COMPOSE=docker-compose pytest

Run one single test module
--------------------------
Expand Down
13 changes: 7 additions & 6 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
PYTEST_RUNNING_IN_CONTAINER = os.environ.get('PYTEST_RUNNING_IN_CONTAINER') == "1"
FORCE_CONTAINER_IPV6 = False # ugly global state to consider containers' IPv6 address instead of IPv4

DOCKER_COMPOSE = os.environ.get('DOCKER_COMPOSE', 'docker compose')

docker_client = docker.from_env()

Expand Down Expand Up @@ -301,19 +302,19 @@ def get_nginx_conf_from_container(container):


def docker_compose_up(compose_file='docker-compose.yml'):
logging.info(f'docker compose -f {compose_file} up -d')
logging.info(f'{DOCKER_COMPOSE} -f {compose_file} up -d')
try:
subprocess.check_output(shlex.split(f'docker compose -f {compose_file} up -d'), stderr=subprocess.STDOUT)
subprocess.check_output(shlex.split(f'{DOCKER_COMPOSE} -f {compose_file} up -d'), stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
pytest.fail(f"Error while runninng 'docker compose -f {compose_file} up -d':\n{e.output}", pytrace=False)
pytest.fail(f"Error while runninng '{DOCKER_COMPOSE} -f {compose_file} up -d':\n{e.output}", pytrace=False)


def docker_compose_down(compose_file='docker-compose.yml'):
logging.info(f'docker compose -f {compose_file} down -v')
logging.info(f'{DOCKER_COMPOSE} -f {compose_file} down -v')
try:
subprocess.check_output(shlex.split(f'docker compose -f {compose_file} down -v'), stderr=subprocess.STDOUT)
subprocess.check_output(shlex.split(f'{DOCKER_COMPOSE} -f {compose_file} down -v'), stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
pytest.fail(f"Error while runninng 'docker compose -f {compose_file} down -v':\n{e.output}", pytrace=False)
pytest.fail(f"Error while runninng '{DOCKER_COMPOSE} -f {compose_file} down -v':\n{e.output}", pytrace=False)


def wait_for_nginxproxy_to_be_ready():
Expand Down

0 comments on commit 4f85eef

Please sign in to comment.