diff --git a/pyproject.toml b/pyproject.toml index 40621e9..7407992 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,6 +86,7 @@ extra-dependencies = [ "pytest-httpx == 0.30.0; python_version >= '3.9'", "pytest-httpx ~= 0.22; python_version < '3.9'", "python-magic", + "pytest-docker ~= 3.1", ] extra-args = [ "--maxprocesses=8", "--pythonwarnings=all" ] diff --git a/tests/conftest.py b/tests/conftest.py index 2a97621..e342a20 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import logging -import os from pathlib import Path from typing import Generator @@ -9,8 +8,27 @@ @pytest.fixture(scope="session") -def tika_host() -> str: - return os.getenv("TIKA_URL", "http://localhost:9998") +def tika_host(docker_services, docker_ip) -> str: + return f"http://{docker_ip}:{docker_services.port_for('tika', 9998)}" + + +@pytest.fixture(scope="session", autouse=True) +def _tika_service(docker_services, tika_host: str) -> None: + def is_responsive(url): + import httpx + + try: + response = httpx.get(url) + if response.status_code == httpx.codes.OK: + return True + except ConnectionError: + return False + + docker_services.wait_until_responsive( + timeout=30.0, + pause=0.1, + check=lambda: is_responsive(tika_host), + ) @pytest.fixture(scope="session") @@ -73,6 +91,11 @@ def sample_xlsx_file(samples_dir: Path) -> Path: return samples_dir / "sample-spreadsheet.xlsx" +@pytest.fixture(scope="session") +def docker_compose_file() -> Path: + return Path(__file__).parent / "docker" / "docker-compose.ci-test.yml" + + @pytest.fixture def tika_client(tika_host: str) -> Generator[TikaClient, None, None]: with TikaClient(tika_url=tika_host, log_level=logging.INFO) as client: diff --git a/.docker/docker-compose.ci-test.yml b/tests/docker/docker-compose.ci-test.yml similarity index 84% rename from .docker/docker-compose.ci-test.yml rename to tests/docker/docker-compose.ci-test.yml index a273f14..8c45482 100644 --- a/.docker/docker-compose.ci-test.yml +++ b/tests/docker/docker-compose.ci-test.yml @@ -3,11 +3,8 @@ # Can be used locally or by the CI to start the necessary container with the # correct networking for the tests -version: "3" services: tika: image: docker.io/apache/tika:latest hostname: tika container_name: tika - network_mode: host - restart: unless-stopped