-
Couldn't load subscription status.
- Fork 344
fix: get_wrapped_container returns container all the time now #906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |||||||||||
| from types import TracebackType | ||||||||||||
| from typing import Any, Callable, Literal, Optional, TypeVar, Union, cast | ||||||||||||
|
|
||||||||||||
| from docker import DockerClient | ||||||||||||
| from docker.models.containers import Container | ||||||||||||
| from testcontainers.core.exceptions import ContainerIsNotRunning, NoSuchPortExposed | ||||||||||||
| from testcontainers.core.waiting_utils import WaitStrategy | ||||||||||||
|
|
||||||||||||
|
|
@@ -137,9 +139,9 @@ def get_logs(self) -> tuple[bytes, bytes]: | |||||||||||
| stdout, stderr = self._docker_compose.get_logs(self.Service) | ||||||||||||
| return stdout.encode(), stderr.encode() | ||||||||||||
|
|
||||||||||||
| def get_wrapped_container(self) -> "ComposeContainer": | ||||||||||||
| def get_wrapped_container(self) -> Container: | ||||||||||||
| """Get the underlying container object for compatibility.""" | ||||||||||||
| return self | ||||||||||||
| return self._docker_compose._get_docker_client().containers.get(self.ID) | ||||||||||||
|
|
||||||||||||
| def reload(self) -> None: | ||||||||||||
| """Reload container information for compatibility with wait strategies.""" | ||||||||||||
|
|
@@ -214,7 +216,9 @@ class DockerCompose: | |||||||||||
| services: Optional[list[str]] = None | ||||||||||||
| docker_command_path: Optional[str] = None | ||||||||||||
| profiles: Optional[list[str]] = None | ||||||||||||
| docker_client_kw: Optional[dict[str, Any]] = None | ||||||||||||
| _wait_strategies: Optional[dict[str, Any]] = field(default=None, init=False, repr=False) | ||||||||||||
| _docker_client: Optional[DockerClient] = field(default=None, init=False, repr=False) | ||||||||||||
|
|
||||||||||||
| def __post_init__(self) -> None: | ||||||||||||
| if isinstance(self.compose_file_name, str): | ||||||||||||
|
|
@@ -259,6 +263,13 @@ def compose_command_property(self) -> list[str]: | |||||||||||
| docker_compose_cmd += ["--env-file", env_file] | ||||||||||||
| return docker_compose_cmd | ||||||||||||
|
|
||||||||||||
| def _get_docker_client(self) -> DockerClient: | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| dc = self._docker_client | ||||||||||||
| if dc is None: | ||||||||||||
| dc = DockerClient(**(self.docker_client_kw or {})) | ||||||||||||
| self._docker_client = dc | ||||||||||||
| return dc | ||||||||||||
|
|
||||||||||||
| def waiting_for(self, strategies: dict[str, WaitStrategy]) -> "DockerCompose": | ||||||||||||
| """ | ||||||||||||
| Set wait strategies for specific services. | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| from typing import Any, Callable, Optional, Protocol, TypeVar, Union, cast | ||
|
|
||
| import wrapt | ||
| from docker.models.containers import Container | ||
| from typing_extensions import Self | ||
|
|
||
| from testcontainers.core.config import testcontainers_config | ||
|
|
@@ -52,7 +53,7 @@ def get_exposed_port(self, port: int) -> int: | |
| """Get the exposed port mapping for the given internal port.""" | ||
| ... | ||
|
|
||
| def get_wrapped_container(self) -> Any: | ||
| def get_wrapped_container(self) -> Container: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We recently had a PR that added a bunch of data classes, I think I should actually be returning one of those here |
||
| """Get the underlying container object.""" | ||
| ... | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dumb question: can
.containers.get(self.ID)return a value other thanContainer, e.g. None?what if the container is not found?