Files
docker-stacks/tests/conftest.py
Ayaz Salikhov b35f1554d6 Test server listening on IPv4/IPv6 (#2255)
* Test server listening on IPv4/IPv6

* Set up Docker in create-dev-env

* Show docker version

* Add info about docker client

* Check requests

* Show docker client version

* Try to pass docker sock

* Fix

* Break fast

* Revert

* Cleanup

* Better naming

* Always use docker.from_env

* Revert "Always use docker.from_env"

This reverts commit d03069ac28.

* Use custom docker client for only one test

* More logs

* Use cont_data_dir in test, so workdir doesn't matter

* Use common variable names

* Move patch to a separate function

* Try to use set-host option

* Use the same docker client in get_health

* Use .api

* Rewrite check_listening.py to use one function for both ipv4 and ipv6

* Add links to explain why we need to set up docker manually
2025-03-20 17:12:22 +00:00

58 lines
1.6 KiB
Python

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging
import os
from collections.abc import Generator
import docker
import pytest # type: ignore
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from tests.utils.tracked_container import TrackedContainer
LOGGER = logging.getLogger(__name__)
@pytest.fixture(scope="session")
def http_client() -> requests.Session:
"""Requests session with retries and backoff."""
s = requests.Session()
retries = Retry(total=5, backoff_factor=1)
s.mount("http://", HTTPAdapter(max_retries=retries))
s.mount("https://", HTTPAdapter(max_retries=retries))
return s
@pytest.fixture(scope="session")
def docker_client() -> docker.DockerClient:
"""Docker client configured based on the host environment"""
client = docker.from_env()
LOGGER.info(f"Docker client created: {client.version()}")
return client
@pytest.fixture(scope="session")
def image_name() -> str:
"""Image name to test"""
return os.environ["TEST_IMAGE"]
@pytest.fixture(scope="function")
def container(
docker_client: docker.DockerClient, image_name: str
) -> Generator[TrackedContainer]:
"""Notebook container with initial configuration appropriate for testing
(e.g., HTTP port exposed to the host for HTTP calls).
Yields the container instance and kills it when the caller is done with it.
"""
container = TrackedContainer(
docker_client,
image_name,
detach=True,
)
yield container
container.remove()