Skip to content

Commit

Permalink
Experiment with using pytest-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpylog committed Oct 9, 2024
1 parent 52a19ef commit 3c1f007
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

Expand Down
29 changes: 26 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
from pathlib import Path
from typing import Generator

Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3c1f007

Please sign in to comment.