1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-08-23 07:51:56 +00:00

tests: DockerComposer connect_to_network except

If running from a container host-network-mode test fail because we cannot connect to host network. This prevents the cleanup.
So make sure we always return network for later removal.

Explicitly return None for readability
This commit is contained in:
Niek
2025-02-27 13:53:35 +01:00
parent 545e9cebb6
commit 58e21618b4

View File

@@ -428,9 +428,15 @@ def connect_to_network(network: Network) -> Optional[Network]:
# Make sure our container is connected to the nginx-proxy's network, # Make sure our container is connected to the nginx-proxy's network,
# but avoid connecting to `none` network (not valid) with `test_server-down` tests # but avoid connecting to `none` network (not valid) with `test_server-down` tests
if network.name not in my_networks and network.name != 'none': if network.name not in my_networks and network.name != 'none':
try:
logging.info(f"Connecting to docker network: {network.name}") logging.info(f"Connecting to docker network: {network.name}")
network.connect(my_container) network.connect(my_container)
return network return network
except docker.errors.APIError as e:
logging.warning(f"Failed to connect to network {network.name}: {e}")
return network # Ensure the network is still tracked for later removal
return None
def disconnect_from_network(network: Network = None): def disconnect_from_network(network: Network = None):