From 04b0181980c0ec51accede0618a53788959e3d95 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Fri, 31 Dec 2021 22:30:49 +1300 Subject: [PATCH] fix: Ensure networks are actually connected to pytest container The `network` object would never be in a list of network names (strings), and without `greedy=True` arg as the `docker-py` API docs note, the containers will not be part of the results, thus always returning an empty list which was not intended.. Now the network will properly match the current networks for pytest container, avoiding duplicate connect attempts, and the network list result will actually have containers to count when filtering by length. --- test/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 3f5f04c..fce4cde 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -367,7 +367,7 @@ def connect_to_network(network): return None # make sure our container is connected to the nginx-proxy's network - if network not in my_networks: + if network.name not in my_networks: logging.info(f"Connecting to docker network: {network.name}") network.connect(my_container) return network @@ -405,7 +405,7 @@ def connect_to_all_networks(): return [] else: # find the list of docker networks - networks = [network for network in docker_client.networks.list() if len(network.containers) > 0 and network.name != 'bridge'] + networks = [network for network in docker_client.networks.list(greedy=True) if len(network.containers) > 0 and network.name != 'bridge'] return [connect_to_network(network) for network in networks]