diff --git a/core/testcontainers/compose/compose.py b/core/testcontainers/compose/compose.py index 86f8b239..9441010d 100644 --- a/core/testcontainers/compose/compose.py +++ b/core/testcontainers/compose/compose.py @@ -173,7 +173,7 @@ class DockerCompose: Wait for the services to be healthy (as per healthcheck definitions in the docker compose configuration) env_file: - Path to an '.env' file containing environment variables + Path(s) to an '.env' file containing environment variables to pass to docker compose. services: The list of services to use from this DockerCompose. @@ -210,7 +210,7 @@ class DockerCompose: build: bool = False wait: bool = True keep_volumes: bool = False - env_file: Optional[str] = None + env_file: Optional[Union[str, list[str]]] = None services: Optional[list[str]] = None docker_command_path: Optional[str] = None profiles: Optional[list[str]] = None @@ -219,6 +219,8 @@ class DockerCompose: def __post_init__(self) -> None: if isinstance(self.compose_file_name, str): self.compose_file_name = [self.compose_file_name] + if isinstance(self.env_file, str): + self.env_file = [self.env_file] def __enter__(self) -> "DockerCompose": self.start() @@ -247,7 +249,8 @@ def compose_command_property(self) -> list[str]: if self.profiles: docker_compose_cmd += [item for profile in self.profiles for item in ["--profile", profile]] if self.env_file: - docker_compose_cmd += ["--env-file", self.env_file] + for env_file in self.env_file: + docker_compose_cmd += ["--env-file", env_file] return docker_compose_cmd def waiting_for(self, strategies: dict[str, WaitStrategy]) -> "DockerCompose":