@@ -180,25 +180,25 @@ def bridge_ip(self, container_id: str) -> str:
180
180
"""
181
181
container = self .get_container (container_id )
182
182
network_name = self .network_name (container_id )
183
- return cast ( str , container ["NetworkSettings" ]["Networks" ][network_name ]["IPAddress" ])
183
+ return str ( container ["NetworkSettings" ]["Networks" ][network_name ]["IPAddress" ])
184
184
185
185
def network_name (self , container_id : str ) -> str :
186
186
"""
187
187
Get the name of the network this container runs on
188
188
"""
189
189
container = self .get_container (container_id )
190
- name = container ["HostConfig" ]["NetworkMode" ]
190
+ name = str ( container ["HostConfig" ]["NetworkMode" ])
191
191
if name == "default" :
192
192
return "bridge"
193
- return cast ( str , name )
193
+ return name
194
194
195
195
def gateway_ip (self , container_id : str ) -> str :
196
196
"""
197
197
Get the gateway ip address for a container.
198
198
"""
199
199
container = self .get_container (container_id )
200
200
network_name = self .network_name (container_id )
201
- return cast ( str , container ["NetworkSettings" ]["Networks" ][network_name ]["Gateway" ])
201
+ return str ( container ["NetworkSettings" ]["Networks" ][network_name ]["Gateway" ])
202
202
203
203
def get_connection_mode (self ) -> ConnectionMode :
204
204
"""
@@ -235,7 +235,8 @@ def host(self) -> str:
235
235
return "localhost"
236
236
if "http" in url .scheme or "tcp" in url .scheme and url .hostname :
237
237
# see https://github.com/testcontainers/testcontainers-python/issues/415
238
- if url .hostname == "localnpipe" and utils .is_windows ():
238
+ hostname = url .hostname
239
+ if not hostname or (hostname == "localnpipe" and utils .is_windows ()):
239
240
return "localhost"
240
241
return cast (str , url .hostname )
241
242
if utils .inside_container () and ("unix" in url .scheme or "npipe" in url .scheme ):
0 commit comments