mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-13 21:12:57 +00:00
Run tests in parallel
This commit is contained in:
18
conftest.py
18
conftest.py
@@ -1,7 +1,9 @@
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
from contextlib import closing
|
||||
import os
|
||||
import logging
|
||||
import socket
|
||||
from typing import Any, Optional
|
||||
|
||||
import docker
|
||||
@@ -16,6 +18,14 @@ from requests.adapters import HTTPAdapter
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def find_free_port() -> str:
|
||||
"""Returns the available host port. Can be called in multiple threads/processes."""
|
||||
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
|
||||
s.bind(("", 0))
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
return s.getsockname()[1]
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def http_client() -> requests.Session:
|
||||
"""Requests session with retries and backoff."""
|
||||
@@ -108,14 +118,6 @@ class TrackedContainer:
|
||||
assert rv == 0 or rv["StatusCode"] == 0
|
||||
return logs
|
||||
|
||||
def get_host_port(self, container_port: str) -> str:
|
||||
"""Returns the host port associated with the tracked container's port."""
|
||||
assert isinstance(self.container, Container)
|
||||
self.container.reload()
|
||||
return self.container.attrs["NetworkSettings"]["Ports"][container_port][0][
|
||||
"HostPort"
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def get_errors(logs: str) -> list[str]:
|
||||
return TrackedContainer._lines_starting_with(logs, "ERROR")
|
||||
|
Reference in New Issue
Block a user