From a94845650a1e6474224e169b1802189c426ecd27 Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Mon, 8 Jun 2020 14:56:19 -0600 Subject: [PATCH 01/15] core/docker-client.py: Windows npipe URIs are rewritten by the docker-py client library to http+docker://localnpipe. Other pipe-like URIs are rewritten this way too. So, the code should detect the http+docker scheme instead of "npipe" and return localhost. Because the check for "http" schemes will inadvertently pick up the http+docker scheme too, do the check for pipes first and for real URLs second. --- testcontainers/core/docker_client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testcontainers/core/docker_client.py b/testcontainers/core/docker_client.py index 7acc1f3e0..ba6943e1f 100644 --- a/testcontainers/core/docker_client.py +++ b/testcontainers/core/docker_client.py @@ -62,11 +62,12 @@ def host(self): except ValueError: return None - if 'http' in url.scheme or 'tcp' in url.scheme: - return url.hostname - if 'unix' in url.scheme or 'npipe' in url.scheme: + if 'unix' in url.scheme or 'http+docker' == url.scheme: if inside_container(): ip_address = default_gateway_ip() if ip_address: return ip_address + return "localhost" + if 'http' in url.scheme or 'tcp' in url.scheme: + return url.hostname return "localhost" From af519c5d715cc8447a1ee9e821de5e1998d624a0 Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Fri, 3 Jul 2020 18:34:02 -0600 Subject: [PATCH 02/15] Add npipe to the check for compatibility. --- testcontainers/core/docker_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcontainers/core/docker_client.py b/testcontainers/core/docker_client.py index ba6943e1f..acc7015a7 100644 --- a/testcontainers/core/docker_client.py +++ b/testcontainers/core/docker_client.py @@ -62,7 +62,7 @@ def host(self): except ValueError: return None - if 'unix' in url.scheme or 'http+docker' == url.scheme: + if 'unix' in url.scheme or 'npipe' in url.scheme or 'http+docker' == url.scheme: if inside_container(): ip_address = default_gateway_ip() if ip_address: From f6929dce4e9d966473eb1d02a25d3aea2c51da0e Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Fri, 19 Mar 2021 17:21:53 -0600 Subject: [PATCH 03/15] Changes from a long time ago. --- .gitignore | 1 + tests/test_nginx_container.py | 2 ++ tests/test_redis.py | 1 + 3 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 89c1c82d5..46cb64b31 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ docs/_build/ .idea/ .venv/ .testrepository/ +/venv/ diff --git a/tests/test_nginx_container.py b/tests/test_nginx_container.py index e2af43932..a1c8fea5b 100644 --- a/tests/test_nginx_container.py +++ b/tests/test_nginx_container.py @@ -1,4 +1,5 @@ import requests +import time from testcontainers.nginx import NginxContainer @@ -9,6 +10,7 @@ def test_docker_run_nginx(): port = nginx.port_to_expose url = "http://{}:{}/".format(nginx.get_container_host_ip(), nginx.get_exposed_port(port)) + time.sleep(5) r = requests.get(url) assert(r.status_code == 200) assert('Welcome to nginx!' in r.text) diff --git a/tests/test_redis.py b/tests/test_redis.py index adcc2b666..8ac400e3a 100644 --- a/tests/test_redis.py +++ b/tests/test_redis.py @@ -6,6 +6,7 @@ def test_docker_run_redis(): config = RedisContainer() with config as redis: + time.sleep(5) client = redis.get_client() p = client.pubsub() p.subscribe('test') From bc969c53680606d7fff6a2e8350f5a6f234fcd38 Mon Sep 17 00:00:00 2001 From: Ashay Thorat Date: Mon, 29 Mar 2021 14:55:41 +0530 Subject: [PATCH 04/15] adding kafka test container support (#127) * adding kafka containers support * Removing the assertions inside the for loop as they are not guarenteed to provide correct feedback --- requirements.in | 2 +- requirements/3.6.txt | 1 + requirements/3.7.txt | 1 + requirements/3.8.txt | 1 + setup.py | 3 +- testcontainers/kafka.py | 84 +++++++++++++++++++++++++++++++++++++++++ tests/test_kafka.py | 31 +++++++++++++++ 7 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 testcontainers/kafka.py create mode 100644 tests/test_kafka.py diff --git a/requirements.in b/requirements.in index 7aece96cb..bcce225ef 100644 --- a/requirements.in +++ b/requirements.in @@ -1,4 +1,4 @@ --e file:.[docker-compose,mysql,oracle,postgresql,selenium,google-cloud-pubsub,mongo,redis,mssqlserver,neo4j] +-e file:.[docker-compose,mysql,oracle,postgresql,selenium,google-cloud-pubsub,mongo,redis,mssqlserver,neo4j,kafka] codecov>=2.1.0 flake8 pytest diff --git a/requirements/3.6.txt b/requirements/3.6.txt index 4f494be4b..034c46197 100644 --- a/requirements/3.6.txt +++ b/requirements/3.6.txt @@ -91,6 +91,7 @@ jinja2==2.11.2 # via sphinx jsonschema==3.2.0 # via docker-compose +kafka-python==2.0.2 # via testcontainers markupsafe==1.1.1 # via jinja2 mccabe==0.6.1 diff --git a/requirements/3.7.txt b/requirements/3.7.txt index 1671545c1..dea3139a8 100644 --- a/requirements/3.7.txt +++ b/requirements/3.7.txt @@ -91,6 +91,7 @@ jinja2==2.11.2 # via sphinx jsonschema==3.2.0 # via docker-compose +kafka-python==2.0.2 # via testcontainers markupsafe==1.1.1 # via jinja2 mccabe==0.6.1 diff --git a/requirements/3.8.txt b/requirements/3.8.txt index 08c4bb553..4959646af 100644 --- a/requirements/3.8.txt +++ b/requirements/3.8.txt @@ -85,6 +85,7 @@ jinja2==2.11.2 # via sphinx jsonschema==3.2.0 # via docker-compose +kafka-python==2.0.2 # via testcontainers markupsafe==1.1.1 # via jinja2 mccabe==0.6.1 diff --git a/setup.py b/setup.py index cfe3dec01..1f8d49779 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,8 @@ 'mongo': ['pymongo'], 'redis': ['redis'], 'mssqlserver': ['pyodbc'], - 'neo4j': ['neo4j'] + 'neo4j': ['neo4j'], + 'kafka': ['kafka-python'] }, long_description_content_type="text/x-rst", long_description=long_description, diff --git a/testcontainers/kafka.py b/testcontainers/kafka.py new file mode 100644 index 000000000..560a80157 --- /dev/null +++ b/testcontainers/kafka.py @@ -0,0 +1,84 @@ +import tarfile +import time +from io import BytesIO +from textwrap import dedent + +from kafka import KafkaConsumer +from kafka.errors import KafkaError + +from testcontainers.core.container import DockerContainer +from testcontainers.core.waiting_utils import wait_container_is_ready + + +class KafkaContainer(DockerContainer): + KAFKA_PORT = 9093 + TC_START_SCRIPT = '/tc-start.sh' + + def __init__(self, image="confluentinc/cp-kafka:5.4.3", port_to_expose=KAFKA_PORT): + super(KafkaContainer, self).__init__(image) + self.port_to_expose = port_to_expose + self.with_exposed_ports(self.port_to_expose) + listeners = 'PLAINTEXT://0.0.0.0:{},BROKER://0.0.0.0:9092'.format(port_to_expose) + self.with_env('KAFKA_LISTENERS', listeners) + self.with_env('KAFKA_LISTENER_SECURITY_PROTOCOL_MAP', + 'BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT') + self.with_env('KAFKA_INTER_BROKER_LISTENER_NAME', 'BROKER') + + self.with_env('KAFKA_BROKER_ID', '1') + self.with_env('KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR', '1') + self.with_env('KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS', '1') + self.with_env('KAFKA_LOG_FLUSH_INTERVAL_MESSAGES', '10000000') + self.with_env('KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS', '0') + + def get_bootstrap_server(self): + host = self.get_container_host_ip() + port = self.get_exposed_port(self.port_to_expose) + return '{}:{}'.format(host, port) + + @wait_container_is_ready() + def _connect(self): + bootstrap_server = self.get_bootstrap_server() + consumer = KafkaConsumer(group_id='test', bootstrap_servers=[bootstrap_server]) + if not consumer.topics(): + raise KafkaError("Unable to connect with kafka container!") + + def tc_start(self): + port = self.get_exposed_port(self.port_to_expose) + listeners = 'PLAINTEXT://localhost:{},BROKER://$(hostname -i):9092'.format(port) + data = ( + dedent( + """ + #!/bin/bash + echo 'clientPort=2181' > zookeeper.properties + echo 'dataDir=/var/lib/zookeeper/data' >> zookeeper.properties + echo 'dataLogDir=/var/lib/zookeeper/log' >> zookeeper.properties + zookeeper-server-start zookeeper.properties & + export KAFKA_ZOOKEEPER_CONNECT='localhost:2181' + export KAFKA_ADVERTISED_LISTENERS={} + . /etc/confluent/docker/bash-config + /etc/confluent/docker/configure + /etc/confluent/docker/launch + """.format(listeners) + ) + .strip() + .encode('utf-8') + ) + self.create_file(data, KafkaContainer.TC_START_SCRIPT) + + def start(self): + script = KafkaContainer.TC_START_SCRIPT + command = 'sh -c "while [ ! -f {} ]; do sleep 0.1; done; sh {}"'.format(script, script) + self.with_command(command) + super().start() + self.tc_start() + self._connect() + return self + + def create_file(self, content: bytes, path: str): + with BytesIO() as archive, tarfile.TarFile(fileobj=archive, mode="w") as tar: + tarinfo = tarfile.TarInfo(name=path) + tarinfo.size = len(content) + tarinfo.mtime = time.time() + tar.addfile(tarinfo, BytesIO(content)) + archive.seek(0) + self.get_wrapped_container().put_archive("/", archive) diff --git a/tests/test_kafka.py b/tests/test_kafka.py new file mode 100644 index 000000000..3f6a80dfc --- /dev/null +++ b/tests/test_kafka.py @@ -0,0 +1,31 @@ +from kafka import KafkaConsumer, KafkaProducer, TopicPartition + +from testcontainers.kafka import KafkaContainer + + +def test_kafka_producer_consumer(): + with KafkaContainer() as container: + produce_and_consume_kafka_message(container) + + +def test_kafka_producer_consumer_custom_port(): + with KafkaContainer(port_to_expose=9888) as container: + assert container.port_to_expose == 9888 + produce_and_consume_kafka_message(container) + + +def produce_and_consume_kafka_message(container): + topic = 'test-topic' + bootstrap_server = container.get_bootstrap_server() + + producer = KafkaProducer(bootstrap_servers=[bootstrap_server]) + producer.send(topic, b"verification message") + producer.flush() + producer.close() + + consumer = KafkaConsumer(bootstrap_servers=[bootstrap_server]) + tp = TopicPartition(topic, 0) + consumer.assign([tp]) + consumer.seek_to_beginning() + assert consumer.end_offsets([tp])[tp] == 1, \ + "Expected exactly one test message to be present on test topic !" From fa36a25b3728b555740d123139ed7bc54b70fc3f Mon Sep 17 00:00:00 2001 From: Petrosyuk <24464919+Petrosyuk@users.noreply.github.com> Date: Thu, 15 Apr 2021 13:42:07 -0400 Subject: [PATCH 05/15] Support passing custom env-file to DockerCompose (#135) * adding support for passing custom env-file (#134) * adding support for passing env-file to DockerCompose (#134) * fixed flake8 * trigger Gihub Actions again Co-authored-by: Anton Petrosyuk --- testcontainers/compose.py | 11 ++++++++--- tests/.env.test | 2 ++ tests/docker-compose-3.yml | 7 +++++++ tests/test_docker_compose.py | 11 ++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/.env.test create mode 100644 tests/docker-compose-3.yml diff --git a/testcontainers/compose.py b/testcontainers/compose.py index 9e595a605..205144107 100644 --- a/testcontainers/compose.py +++ b/testcontainers/compose.py @@ -5,9 +5,8 @@ Allows to spin up services configured via :code:`docker-compose.yml`. """ -import subprocess - import requests +import subprocess from testcontainers.core.waiting_utils import wait_container_is_ready from testcontainers.core.exceptions import NoSuchPortExposed @@ -55,16 +54,19 @@ class DockerCompose(object): expose: - "5555" """ + def __init__( self, filepath, compose_file_name="docker-compose.yml", - pull=False): + pull=False, + env_file=None): self.filepath = filepath self.compose_file_names = compose_file_name if isinstance( compose_file_name, (list, tuple) ) else [compose_file_name] self.pull = pull + self.env_file = env_file def __enter__(self): self.start() @@ -77,12 +79,15 @@ def docker_compose_command(self): docker_compose_cmd = ['docker-compose'] for file in self.compose_file_names: docker_compose_cmd += ['-f', file] + if self.env_file: + docker_compose_cmd += ['--env-file', self.env_file] return docker_compose_cmd def start(self): if self.pull: pull_cmd = self.docker_compose_command() + ['pull'] subprocess.call(pull_cmd, cwd=self.filepath) + up_cmd = self.docker_compose_command() + ['up', '-d'] subprocess.call(up_cmd, cwd=self.filepath) diff --git a/tests/.env.test b/tests/.env.test new file mode 100644 index 000000000..23e151152 --- /dev/null +++ b/tests/.env.test @@ -0,0 +1,2 @@ +TAG_MYSQL_ALLOW_EMPTY_PASSWORD="true" +TAG_TEST_ASSERT_KEY="test_is_passed" \ No newline at end of file diff --git a/tests/docker-compose-3.yml b/tests/docker-compose-3.yml new file mode 100644 index 000000000..35448cb7e --- /dev/null +++ b/tests/docker-compose-3.yml @@ -0,0 +1,7 @@ +mysql: + image: mysql + ports: + - "3306:3306" + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: ${TAG_MYSQL_ALLOW_EMPTY_PASSWORD} + TEST_ASSERT_KEY: ${TAG_TEST_ASSERT_KEY} \ No newline at end of file diff --git a/tests/test_docker_compose.py b/tests/test_docker_compose.py index d13cbc329..747be5e16 100644 --- a/tests/test_docker_compose.py +++ b/tests/test_docker_compose.py @@ -1,4 +1,5 @@ import pytest +import subprocess from testcontainers.compose import DockerCompose from testcontainers.core.docker_client import DockerClient @@ -6,7 +7,7 @@ def test_can_spawn_service_via_compose(): - with DockerCompose("tests") as compose: + with DockerCompose('tests') as compose: host = compose.get_service_host("hub", 4444) port = compose.get_service_port("hub", 4444) assert host == "0.0.0.0" @@ -53,3 +54,11 @@ def test_can_get_logs(): compose.wait_for("http://%s:4444/wd/hub" % docker.host()) stdout, stderr = compose.get_logs() assert stdout, 'There should be something on stdout' + + +def test_can_pass_env_params_by_env_file(): + with DockerCompose('tests', compose_file_name='docker-compose-3.yml', + env_file='.env.test') as _: + check_env_is_set_cmd = 'docker exec tests_mysql_1 printenv | grep TEST_ASSERT_KEY'.split() + out = subprocess.run(check_env_is_set_cmd, stdout=subprocess.PIPE) + assert out.stdout.decode('utf-8').splitlines()[0], 'test_is_passed' From 1a143b0bef3732c8d13f462672da4045356c0861 Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Thu, 3 Jun 2021 11:02:52 +0300 Subject: [PATCH 06/15] add host to fix db connection on windows --- testcontainers/core/generic.py | 5 +++-- testcontainers/postgres.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/testcontainers/core/generic.py b/testcontainers/core/generic.py index 1cce71afd..c2832c963 100644 --- a/testcontainers/core/generic.py +++ b/testcontainers/core/generic.py @@ -29,10 +29,11 @@ def _connect(self): def get_connection_url(self): raise NotImplementedError - def _create_connection_url(self, dialect, username, password, port, db_name=None): + def _create_connection_url(self, dialect, username, password, host=None, port=None, db_name=None): if self._container is None: raise RuntimeError("container has not been started") - host = self.get_container_host_ip() + if not host: + host = self.get_container_host_ip() port = self.get_exposed_port(port) url = "{dialect}://{username}:{password}@{host}:{port}".format( dialect=dialect, username=username, password=password, host=host, port=port diff --git a/testcontainers/postgres.py b/testcontainers/postgres.py index be9b514ab..502b70c12 100644 --- a/testcontainers/postgres.py +++ b/testcontainers/postgres.py @@ -46,9 +46,10 @@ def _configure(self): self.with_env("POSTGRES_PASSWORD", self.POSTGRES_PASSWORD) self.with_env("POSTGRES_DB", self.POSTGRES_DB) - def get_connection_url(self): + def get_connection_url(self, host="localhost"): return super()._create_connection_url(dialect="postgresql+psycopg2", username=self.POSTGRES_USER, password=self.POSTGRES_PASSWORD, db_name=self.POSTGRES_DB, + host=host, port=self.port_to_expose) From 50f8d8ca1b031b1a2cf5c594c857fc16cf7d226b Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Thu, 3 Jun 2021 11:07:40 +0300 Subject: [PATCH 07/15] fix flake --- testcontainers/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testcontainers/core/generic.py b/testcontainers/core/generic.py index c2832c963..a486801f5 100644 --- a/testcontainers/core/generic.py +++ b/testcontainers/core/generic.py @@ -29,7 +29,8 @@ def _connect(self): def get_connection_url(self): raise NotImplementedError - def _create_connection_url(self, dialect, username, password, host=None, port=None, db_name=None): + def _create_connection_url(self, dialect, username, password, + host=None, port=None, db_name=None): if self._container is None: raise RuntimeError("container has not been started") if not host: From 83abd93791dbc3932884e2343c2bd4c6ed42ae77 Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Thu, 15 Jul 2021 11:57:47 -0600 Subject: [PATCH 08/15] Ignore .vscode directory. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46cb64b31..1381dc7d9 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ docs/_build/ .venv/ .testrepository/ /venv/ +.vscode/ \ No newline at end of file From 4b47d7e05dce67838305f426499a300ef53a90ac Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Mon, 8 Jun 2020 14:56:19 -0600 Subject: [PATCH 09/15] core/docker-client.py: Windows npipe URIs are rewritten by the docker-py client library to http+docker://localnpipe. Other pipe-like URIs are rewritten this way too. So, the code should detect the http+docker scheme instead of "npipe" and return localhost. Because the check for "http" schemes will inadvertently pick up the http+docker scheme too, do the check for pipes first and for real URLs second. --- testcontainers/core/docker_client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testcontainers/core/docker_client.py b/testcontainers/core/docker_client.py index 7acc1f3e0..ba6943e1f 100644 --- a/testcontainers/core/docker_client.py +++ b/testcontainers/core/docker_client.py @@ -62,11 +62,12 @@ def host(self): except ValueError: return None - if 'http' in url.scheme or 'tcp' in url.scheme: - return url.hostname - if 'unix' in url.scheme or 'npipe' in url.scheme: + if 'unix' in url.scheme or 'http+docker' == url.scheme: if inside_container(): ip_address = default_gateway_ip() if ip_address: return ip_address + return "localhost" + if 'http' in url.scheme or 'tcp' in url.scheme: + return url.hostname return "localhost" From 3f702d567c109701be1035882d5a35408524141f Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Fri, 3 Jul 2020 18:34:02 -0600 Subject: [PATCH 10/15] Add npipe to the check for compatibility. --- testcontainers/core/docker_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcontainers/core/docker_client.py b/testcontainers/core/docker_client.py index ba6943e1f..acc7015a7 100644 --- a/testcontainers/core/docker_client.py +++ b/testcontainers/core/docker_client.py @@ -62,7 +62,7 @@ def host(self): except ValueError: return None - if 'unix' in url.scheme or 'http+docker' == url.scheme: + if 'unix' in url.scheme or 'npipe' in url.scheme or 'http+docker' == url.scheme: if inside_container(): ip_address = default_gateway_ip() if ip_address: From 5ae7eaa785b66651cf8eb6ab060147154bc6ef82 Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Fri, 19 Mar 2021 17:21:53 -0600 Subject: [PATCH 11/15] Changes from a long time ago. --- .gitignore | 1 + tests/test_nginx_container.py | 2 ++ tests/test_redis.py | 1 + 3 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 89c1c82d5..46cb64b31 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ docs/_build/ .idea/ .venv/ .testrepository/ +/venv/ diff --git a/tests/test_nginx_container.py b/tests/test_nginx_container.py index e2af43932..a1c8fea5b 100644 --- a/tests/test_nginx_container.py +++ b/tests/test_nginx_container.py @@ -1,4 +1,5 @@ import requests +import time from testcontainers.nginx import NginxContainer @@ -9,6 +10,7 @@ def test_docker_run_nginx(): port = nginx.port_to_expose url = "http://{}:{}/".format(nginx.get_container_host_ip(), nginx.get_exposed_port(port)) + time.sleep(5) r = requests.get(url) assert(r.status_code == 200) assert('Welcome to nginx!' in r.text) diff --git a/tests/test_redis.py b/tests/test_redis.py index adcc2b666..8ac400e3a 100644 --- a/tests/test_redis.py +++ b/tests/test_redis.py @@ -6,6 +6,7 @@ def test_docker_run_redis(): config = RedisContainer() with config as redis: + time.sleep(5) client = redis.get_client() p = client.pubsub() p.subscribe('test') From a331bb2df3874e6cc3967e138a09e56f7889830a Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Thu, 15 Jul 2021 11:57:47 -0600 Subject: [PATCH 12/15] Ignore .vscode directory. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46cb64b31..1381dc7d9 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ docs/_build/ .venv/ .testrepository/ /venv/ +.vscode/ \ No newline at end of file From ed5299749623b4d697b0950ef221358c49b1fa4f Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Thu, 15 Jul 2021 12:09:11 -0600 Subject: [PATCH 13/15] Add a description of this fork. --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 5fae0ae5b..46fedf1a7 100644 --- a/README.rst +++ b/README.rst @@ -10,6 +10,8 @@ testcontainers-python Python port for testcontainers-java that allows using docker containers for functional and integration testing. Testcontainers-python provides capabilities to spin up docker containers (such as a database, Selenium web browser, or any other container) for testing. +This fork of testcontainers-python fixes bugs in upstream's Windows support, and it also works on Linux and MacOS. + Currently available features: * Selenium Grid containers From e52150c1c409f3a9b8aa68abfa22dcbe0e7cb505 Mon Sep 17 00:00:00 2001 From: Andrew Post Date: Thu, 15 Jul 2021 16:31:45 -0600 Subject: [PATCH 14/15] Add to the README.rst. --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index 46fedf1a7..9c771f99d 100644 --- a/README.rst +++ b/README.rst @@ -74,6 +74,10 @@ We recommend you use a `virtual environment Date: Thu, 15 Jul 2021 18:23:40 -0600 Subject: [PATCH 15/15] Avoid test failures, and document the bug in Docker Desktop for Windows that was causing them. --- README.rst | 4 +++- tests/test_db_containers.py | 2 +- tests/test_kafka.py | 4 ++++ tests/test_new_docker_api.py | 2 ++ tests/test_nginx_container.py | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 9c771f99d..29f9695bb 100644 --- a/README.rst +++ b/README.rst @@ -76,7 +76,9 @@ We recommend you use a `virtual environment 0 diff --git a/tests/test_nginx_container.py b/tests/test_nginx_container.py index a1c8fea5b..0e8ad78a7 100644 --- a/tests/test_nginx_container.py +++ b/tests/test_nginx_container.py @@ -7,10 +7,10 @@ def test_docker_run_nginx(): nginx_container = NginxContainer("nginx:1.13.8") with nginx_container as nginx: + time.sleep(5) port = nginx.port_to_expose url = "http://{}:{}/".format(nginx.get_container_host_ip(), nginx.get_exposed_port(port)) - time.sleep(5) r = requests.get(url) assert(r.status_code == 200) assert('Welcome to nginx!' in r.text)