Skip to content

Commit d63cab3

Browse files
committed
Proposed fix for pytest-docker-compose#32, simply checks for not None on port_configs
1 parent d533499 commit d63cab3

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ For performance reasons, the plugin is not enabled by default, so you must activ
3838
3939
See `Installing and Using Plugins`_ for more information.
4040

41-
To interact with Docker containers in your tests, use the following fixtures:
41+
To interact with Docker containers in your tests, use the following fixtures, these fixtures tell docker-compose to start all the services and then they fetch the associated container:
4242

4343
``function_scoped_container_getter``
4444
An object that fetches containers of the Docker ``compose.container.Container`` objects running during the test. The containers are fetched using ``function_scoped_container_getter.get('service_name')`` These containers each have an extra attribute called ``network_info`` added to them. This attribute has a list of ``pytest_docker_compose.NetworkInfo`` objects.
4545

46-
This information can be used to configure API clients and other objects that
47-
will connect to services exposed by the Docker containers in your tests.
46+
This information can be used to configure API clients and other objects that will connect to services exposed by the Docker containers in your tests.
4847

4948
``NetworkInfo`` is a container with the following fields:
5049

@@ -93,7 +92,7 @@ Here's an example of a fixture called ``wait_for_api`` that waits for an HTTP se
9392
9493
pytest_plugins = ["docker_compose"]
9594
96-
95+
# Invoking this fixture: 'function_scoped_container_getter' starts all services
9796
@pytest.fixture(scope="function")
9897
def wait_for_api(function_scoped_container_getter):
9998
"""Wait for the api from my_api_service to become responsive"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
name="pytest-docker-compose",
88
description="Manages Docker containers during your integration tests",
99
long_description=long_description,
10-
version="3.1.0",
10+
version="3.1.1",
1111
author="Roald Storm",
1212
author_email="[email protected]",
1313
url="https://github.com/pytest-docker-compose/pytest-docker-compose",

src/pytest_docker_compose/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ def create_network_info_for_container(container: Container):
4343
Generates :py:class:`NetworkInfo` instances corresponding to all available
4444
port bindings in a container
4545
"""
46+
# If ports are exposed by the docker container but not by docker expose
47+
# container.ports looks like this:
48+
# container.ports == {'4369/tcp': None,
49+
# '5984/tcp': [{'HostIp': '0.0.0.0', 'HostPort': '32872'}],
50+
# '9100/tcp': None}
4651
return [NetworkInfo(container_port=container_port,
4752
hostname=port_config["HostIp"] or "localhost",
4853
host_port=port_config["HostPort"],)
49-
for container_port, port_configs in
50-
container.ports.items()
51-
for port_config in port_configs]
54+
for container_port, port_configs in container.ports.items()
55+
if port_configs is not None for port_config in port_configs]
5256

5357

5458
class DockerComposePlugin:

0 commit comments

Comments
 (0)