diff --git a/compose/setup.py b/compose/setup.py index bfe128e2..a0b0f842 100644 --- a/compose/setup.py +++ b/compose/setup.py @@ -12,7 +12,8 @@ url="https://github.com/testcontainers/testcontainers-python", install_requires=[ "testcontainers-core", - "docker-compose", + # docker compose support has been removed to fix dependency issues in the build + # "docker-compose", ], python_requires=">=3.7", ) diff --git a/compose/tests/test_docker_compose.py b/compose/tests/test_docker_compose.py index da611f1c..265973ba 100644 --- a/compose/tests/test_docker_compose.py +++ b/compose/tests/test_docker_compose.py @@ -11,6 +11,7 @@ ROOT = os.path.dirname(__file__) +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_spawn_service_via_compose(): with DockerCompose(ROOT) as compose: host = compose.get_service_host("hub", 4444) @@ -19,6 +20,7 @@ def test_can_spawn_service_via_compose(): assert port == "4444" +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_pull_images_before_spawning_service_via_compose(): with DockerCompose(ROOT, pull=True) as compose: host = compose.get_service_host("hub", 4444) @@ -27,6 +29,7 @@ def test_can_pull_images_before_spawning_service_via_compose(): assert port == "4444" +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_build_images_before_spawning_service_via_compose(): with patch.object(DockerCompose, "_call_command") as call_mock: with DockerCompose(ROOT, build=True) as compose: @@ -39,6 +42,7 @@ def test_can_build_images_before_spawning_service_via_compose(): assert "--build" in docker_compose_cmd +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_specify_services(): with patch.object(DockerCompose, "_call_command") as call_mock: with DockerCompose(ROOT, services=["hub", "firefox"]) as compose: @@ -52,6 +56,7 @@ def test_can_specify_services(): assert "chrome" not in docker_compose_cmd +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") @pytest.mark.parametrize("should_run_hub", [ [True], [False], @@ -71,23 +76,27 @@ def test_can_run_specific_services(should_run_hub: bool): assert compose.get_service_host("hub", 4444) +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_throw_exception_if_no_port_exposed(): with DockerCompose(ROOT) as compose: with pytest.raises(NoSuchPortExposed): compose.get_service_host("hub", 5555) +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_compose_wait_for_container_ready(): with DockerCompose(ROOT) as compose: docker = DockerClient() compose.wait_for("http://%s:4444/wd/hub" % docker.host()) +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_compose_can_wait_for_logs(): with DockerCompose(filepath=ROOT, compose_file_name="docker-compose-4.yml") as compose: wait_for_logs(compose, "Hello from Docker!") +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_parse_multiple_compose_files(): with DockerCompose(filepath=ROOT, compose_file_name=["docker-compose.yml", "docker-compose-2.yml"]) as compose: @@ -102,6 +111,7 @@ def test_can_parse_multiple_compose_files(): assert port == "4444" +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_get_logs(): with DockerCompose(ROOT) as compose: docker = DockerClient() @@ -110,6 +120,7 @@ def test_can_get_logs(): assert stdout, 'There should be something on stdout' +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_pass_env_params_by_env_file(): with DockerCompose(ROOT, compose_file_name='docker-compose-3.yml', env_file='.env.test') as compose: @@ -117,6 +128,7 @@ def test_can_pass_env_params_by_env_file(): assert stdout.splitlines()[0], 'test_has_passed' +@pytest.mark.skip(reason="compose support has been removed to fix dependency issues in the build") def test_can_exec_commands(): with DockerCompose(ROOT) as compose: result = compose.exec_in_container('hub', ['echo', 'my_test']) diff --git a/elasticsearch/testcontainers/elasticsearch/__init__.py b/elasticsearch/testcontainers/elasticsearch/__init__.py index ec945833..50026ae6 100644 --- a/elasticsearch/testcontainers/elasticsearch/__init__.py +++ b/elasticsearch/testcontainers/elasticsearch/__init__.py @@ -12,7 +12,7 @@ # under the License. import logging import re -import urllib +import urllib.request from typing import Dict from urllib.error import URLError @@ -88,7 +88,7 @@ def __init__(self, image: str = "elasticsearch", port: int = 9200, **kwargs) -> @wait_container_is_ready(URLError) def _connect(self) -> None: - res = urllib.request.urlopen(self.get_url()) + res = urllib.request.urlopen(self.get_url(), timeout=1) if res.status != 200: raise Exception() diff --git a/elasticsearch/tests/test_elasticsearch.py b/elasticsearch/tests/test_elasticsearch.py index 6bbc57fd..16e44d0f 100644 --- a/elasticsearch/tests/test_elasticsearch.py +++ b/elasticsearch/tests/test_elasticsearch.py @@ -1,5 +1,5 @@ import json -import urllib +import urllib.request import pytest from testcontainers.elasticsearch import ElasticSearchContainer @@ -8,6 +8,8 @@ # The versions below were the current supported versions at time of writing (2022-08-11) @pytest.mark.parametrize('version', ['6.8.23', '7.17.5', '8.3.3']) def test_docker_run_elasticsearch(version): - with ElasticSearchContainer(f'elasticsearch:{version}') as es: + # adding the mem_limit as per: https://stackoverflow.com/a/75701019 + # could also add (but not necessary): .with_env('discovery.type', 'single-node') + with ElasticSearchContainer(f'elasticsearch:{version}', mem_limit='3G') as es: resp = urllib.request.urlopen(es.get_url()) assert json.loads(resp.read().decode())['version']['number'] == version diff --git a/nginx/testcontainers/nginx/__init__.py b/nginx/testcontainers/nginx/__init__.py index 0226d700..d0680f19 100644 --- a/nginx/testcontainers/nginx/__init__.py +++ b/nginx/testcontainers/nginx/__init__.py @@ -10,8 +10,13 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import urllib.error +import urllib.parse +import urllib.request + from testcontainers.core.container import DockerContainer from testcontainers.core.utils import raise_for_deprecated_parameter +from testcontainers.core.waiting_utils import wait_container_is_ready class NginxContainer(DockerContainer): @@ -20,3 +25,17 @@ def __init__(self, image: str = "nginx:latest", port: int = 80, **kwargs) -> Non super(NginxContainer, self).__init__(image, **kwargs) self.port = port self.with_exposed_ports(self.port) + + def start(self) -> 'NginxContainer': + super().start() + + host = self.get_container_host_ip() + port = str(self.get_exposed_port(self.port)) + self._connect(host, port) + + return self + + @wait_container_is_ready(urllib.error.URLError) + def _connect(self, host: str, port: str) -> None: + url = urllib.parse.urlunsplit(('http', f'{host}:{port}', '', '', '')) + urllib.request.urlopen(url, timeout=1) diff --git a/requirements/macos-latest-3.10.txt b/requirements/macos-latest-3.10.txt index bffd3237..7686dbaf 100644 --- a/requirements/macos-latest-3.10.txt +++ b/requirements/macos-latest-3.10.txt @@ -138,8 +138,6 @@ docker[ssh]==6.1.3 # via # docker-compose # testcontainers-core -docker-compose==1.29.2 - # via testcontainers-compose dockerpty==0.4.1 # via docker-compose docopt==0.6.2 @@ -317,8 +315,6 @@ pytz==2023.3 # via # clickhouse-driver # neo4j -pyyaml==5.4.1 - # via docker-compose readme-renderer==37.3 # via twine redis==4.5.5 diff --git a/requirements/ubuntu-latest-3.10.txt b/requirements/ubuntu-latest-3.10.txt index 5a06928f..49de4297 100644 --- a/requirements/ubuntu-latest-3.10.txt +++ b/requirements/ubuntu-latest-3.10.txt @@ -139,8 +139,6 @@ docker[ssh]==6.1.3 # via # docker-compose # testcontainers-core -docker-compose==1.29.2 - # via testcontainers-compose dockerpty==0.4.1 # via docker-compose docopt==0.6.2 @@ -322,8 +320,6 @@ pytz==2023.3 # via # clickhouse-driver # neo4j -pyyaml==5.4.1 - # via docker-compose readme-renderer==37.3 # via twine redis==4.5.5 diff --git a/requirements/ubuntu-latest-3.11.txt b/requirements/ubuntu-latest-3.11.txt index 107b6742..88b8cbc6 100644 --- a/requirements/ubuntu-latest-3.11.txt +++ b/requirements/ubuntu-latest-3.11.txt @@ -137,8 +137,6 @@ docker[ssh]==6.1.3 # via # docker-compose # testcontainers-core -docker-compose==1.29.2 - # via testcontainers-compose dockerpty==0.4.1 # via docker-compose docopt==0.6.2 @@ -317,8 +315,6 @@ pytz==2023.3 # via # clickhouse-driver # neo4j -pyyaml==5.4.1 - # via docker-compose readme-renderer==37.3 # via twine redis==4.5.5 diff --git a/requirements/ubuntu-latest-3.7.txt b/requirements/ubuntu-latest-3.7.txt index b7197ef2..97d15cdb 100644 --- a/requirements/ubuntu-latest-3.7.txt +++ b/requirements/ubuntu-latest-3.7.txt @@ -143,8 +143,6 @@ docker[ssh]==6.1.3 # via # docker-compose # testcontainers-core -docker-compose==1.29.2 - # via testcontainers-compose dockerpty==0.4.1 # via docker-compose docopt==0.6.2 @@ -337,8 +335,6 @@ pytz==2023.3 # babel # clickhouse-driver # neo4j -pyyaml==5.4.1 - # via docker-compose readme-renderer==37.3 # via twine redis==4.5.5 diff --git a/requirements/ubuntu-latest-3.8.txt b/requirements/ubuntu-latest-3.8.txt index 58cabaab..511e1cc5 100644 --- a/requirements/ubuntu-latest-3.8.txt +++ b/requirements/ubuntu-latest-3.8.txt @@ -141,8 +141,6 @@ docker[ssh]==6.1.3 # via # docker-compose # testcontainers-core -docker-compose==1.29.2 - # via testcontainers-compose dockerpty==0.4.1 # via docker-compose docopt==0.6.2 @@ -328,8 +326,6 @@ pytz==2023.3 # babel # clickhouse-driver # neo4j -pyyaml==5.4.1 - # via docker-compose readme-renderer==37.3 # via twine redis==4.5.5 diff --git a/requirements/ubuntu-latest-3.9.txt b/requirements/ubuntu-latest-3.9.txt index bf3410c4..1fdec3d9 100644 --- a/requirements/ubuntu-latest-3.9.txt +++ b/requirements/ubuntu-latest-3.9.txt @@ -139,8 +139,6 @@ docker[ssh]==6.1.3 # via # docker-compose # testcontainers-core -docker-compose==1.29.2 - # via testcontainers-compose dockerpty==0.4.1 # via docker-compose docopt==0.6.2 @@ -323,8 +321,6 @@ pytz==2023.3 # via # clickhouse-driver # neo4j -pyyaml==5.4.1 - # via docker-compose readme-renderer==37.3 # via twine redis==4.5.5 diff --git a/requirements/windows-latest-3.10.txt b/requirements/windows-latest-3.10.txt index 4c6dd2f8..9d7d4581 100644 --- a/requirements/windows-latest-3.10.txt +++ b/requirements/windows-latest-3.10.txt @@ -144,8 +144,6 @@ docker[ssh]==6.1.3 # via # docker-compose # testcontainers-core -docker-compose==1.29.2 - # via testcontainers-compose dockerpty==0.4.1 # via docker-compose docopt==0.6.2 @@ -327,8 +325,6 @@ pywin32==306 # via docker pywin32-ctypes==0.2.0 # via keyring -pyyaml==5.4.1 - # via docker-compose readme-renderer==37.3 # via twine redis==4.5.5 diff --git a/selenium/testcontainers/selenium/__init__.py b/selenium/testcontainers/selenium/__init__.py index 6b207078..1495947b 100644 --- a/selenium/testcontainers/selenium/__init__.py +++ b/selenium/testcontainers/selenium/__init__.py @@ -12,10 +12,11 @@ # under the License. from selenium import webdriver +from selenium.webdriver.common.options import ArgOptions from testcontainers.core.container import DockerContainer from testcontainers.core.waiting_utils import wait_container_is_ready -from typing import Optional -import urllib3 +from typing import Any, Dict, Optional +import urllib3.exceptions IMAGES = { @@ -24,7 +25,7 @@ } -def get_image_name(capabilities: str) -> str: +def get_image_name(capabilities: Dict[str, Any]) -> str: return IMAGES[capabilities['browserName']] @@ -45,9 +46,9 @@ class BrowserWebDriverContainer(DockerContainer): You can easily change browser by passing :code:`DesiredCapabilities.FIREFOX` instead. """ - def __init__(self, capabilities: str, image: Optional[str] = None, port: int = 4444, + def __init__(self, capabilities: Dict[str, Any], image: Optional[str] = None, port: int = 4444, vnc_port: int = 5900, **kwargs) -> None: - self.capabilities = capabilities + self.capabilities = capabilities or webdriver.DesiredCapabilities.CHROME self.image = image or get_image_name(capabilities) self.port = port self.vnc_port = vnc_port @@ -60,9 +61,13 @@ def _configure(self) -> None: @wait_container_is_ready(urllib3.exceptions.HTTPError) def _connect(self) -> webdriver.Remote: + options = ArgOptions() + caps = options.capabilities + for k, v in self.capabilities.items(): caps[k] = v # noqa + return webdriver.Remote( command_executor=(self.get_connection_url()), - desired_capabilities=self.capabilities) + options=options) def get_driver(self) -> webdriver.Remote: return self._connect() diff --git a/selenium/tests/test_selenium.py b/selenium/tests/test_selenium.py index 0b25cd5e..e038cab7 100644 --- a/selenium/tests/test_selenium.py +++ b/selenium/tests/test_selenium.py @@ -4,7 +4,9 @@ from testcontainers.core.utils import is_arm -@pytest.mark.parametrize("caps", [DesiredCapabilities.CHROME, DesiredCapabilities.FIREFOX]) +@pytest.mark.parametrize("caps", + [DesiredCapabilities.CHROME, DesiredCapabilities.FIREFOX], + ids=['chrome', 'ff']) def test_webdriver_container_container(caps): if is_arm(): pytest.skip('https://github.com/SeleniumHQ/docker-selenium/issues/1076')