Skip to content

Commit

Permalink
fix: enable unit tests to run when Docker subsystem is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
bsbodden committed Sep 9, 2024
1 parent f040df8 commit 958c851
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions libs/redis/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import subprocess

import pytest

Expand All @@ -16,18 +17,21 @@ def redis_container() -> DockerCompose:
# Set the default Redis version if not already set
os.environ.setdefault("REDIS_VERSION", "edge")

compose = DockerCompose(
"tests", compose_file_name="docker-compose.yml", pull=True
)
compose.start()
try:
compose = DockerCompose(
"tests", compose_file_name="docker-compose.yml", pull=True
)
compose.start()

redis_host, redis_port = compose.get_service_host_and_port("redis", 6379)
redis_url = f"redis://{redis_host}:{redis_port}"
os.environ["REDIS_URL"] = redis_url
redis_host, redis_port = compose.get_service_host_and_port("redis", 6379)
redis_url = f"redis://{redis_host}:{redis_port}"
os.environ["REDIS_URL"] = redis_url

yield compose
yield compose

compose.stop()
compose.stop()
except subprocess.CalledProcessError:
yield None


@pytest.fixture(scope="session")
Expand Down

0 comments on commit 958c851

Please sign in to comment.