diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 259d7efa..b1660715 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -246,9 +246,7 @@ def _f(**kwargs: Any) -> Config: platform_api=platform_api_config, platform_config=platform_config, s3=s3_config, - logs=LogsConfig( - storage_type=LogsStorageType.S3, cleanup_interval_sec=0.5 - ), + logs=LogsConfig(storage_type=LogsStorageType.S3, cleanup_interval_sec=0.5), kube=kube_config, registry=registry_config, container_runtime=container_runtime_config, diff --git a/tests/integration/conftest_config.py b/tests/integration/conftest_config.py index 14e3e195..c4bf1376 100644 --- a/tests/integration/conftest_config.py +++ b/tests/integration/conftest_config.py @@ -52,11 +52,12 @@ async def _wait_for_platform_api_config( ) -> None: while True: import warnings + with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) try: async with create_platform_api_client( - platform_api_config.url, platform_api_config.token + platform_api_config.url, platform_api_config.token ): return except Exception: diff --git a/tests/integration/conftest_kube.py b/tests/integration/conftest_kube.py index eebeb33c..203d3f01 100644 --- a/tests/integration/conftest_kube.py +++ b/tests/integration/conftest_kube.py @@ -20,7 +20,6 @@ class MyKubeClient(KubeClient): - # TODO (A Yushkovskiy, 30-May-2019) delete pods automatically async def create_pod(self, job_pod_descriptor: dict[str, Any]) -> str: diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 4bb93592..952cb3ee 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -1037,7 +1037,8 @@ async def test_attach_forbidden( async with client.ws_connect(url): pass except WSServerHandshakeError as e: - assert e.headers and e.headers.get("X-Error") + assert e.headers + assert e.headers.get("X-Error") assert e.message == "Invalid response status" assert e.status == HTTPUnauthorized.status_code @@ -1401,7 +1402,6 @@ async def test_kill( jobs_client: JobsClient, infinite_job: str, ) -> None: - headers = jobs_client.headers url = monitoring_api.generate_kill_url(infinite_job) diff --git a/tests/integration/test_jobs_service.py b/tests/integration/test_jobs_service.py index b9b60345..26a6a18a 100644 --- a/tests/integration/test_jobs_service.py +++ b/tests/integration/test_jobs_service.py @@ -317,7 +317,8 @@ async def test_save_commit_fails_with_exception( async def test_get_available_jobs_count(self, jobs_service: JobsService) -> None: result = await jobs_service.get_available_jobs_counts() - assert result and "cpu-small" in result + assert result + assert "cpu-small" in result async def test_mark_logs_dropped( self, diff --git a/tests/integration/test_kube.py b/tests/integration/test_kube.py index a4227f57..2a325a1d 100644 --- a/tests/integration/test_kube.py +++ b/tests/integration/test_kube.py @@ -10,7 +10,7 @@ from contextlib import AbstractAsyncContextManager from datetime import datetime, timedelta, timezone from pathlib import Path -from typing import Any, Union +from typing import Any from unittest import mock from uuid import uuid4 @@ -1189,7 +1189,7 @@ async def stop_func() -> bool: def run_log_reader( name: str, delay: float = 0, timeout_s: float = 60.0 ) -> None: - async def coro() -> Union[bytes, Exception]: + async def coro() -> bytes | Exception: await asyncio.sleep(delay) try: async with timeout(timeout_s): @@ -1271,7 +1271,7 @@ async def stop_func() -> bool: def run_log_reader( name: str, delay: float = 0, timeout_s: float = 60.0 ) -> None: - async def coro() -> Union[bytes, Exception]: + async def coro() -> bytes | Exception: await asyncio.sleep(delay) try: async with timeout(timeout_s): @@ -1358,7 +1358,7 @@ async def stop_func() -> bool: def run_log_reader( name: str, delay: float = 0, timeout_s: float = 60.0 ) -> None: - async def coro() -> Union[bytes, Exception]: + async def coro() -> bytes | Exception: await asyncio.sleep(delay) try: async with timeout(timeout_s): diff --git a/tests/unit/test_logs.py b/tests/unit/test_logs.py index 7bb865af..8bdebb03 100644 --- a/tests/unit/test_logs.py +++ b/tests/unit/test_logs.py @@ -1,6 +1,6 @@ import json from collections.abc import AsyncIterator, Callable, Sequence -from datetime import datetime, timezone, timedelta +from datetime import datetime, timedelta, timezone from typing import Any from unittest import mock @@ -37,12 +37,11 @@ def setup_s3_key_content( s3_client: mock.Mock, ) -> Callable[[dict[str, list[str]]], None]: def _setup(content: dict[str, list[str]]) -> None: - async def get_object( - Key: str, *args: Any, **kwargs: Any - ) -> dict[str, Any]: + async def get_object(Key: str, *args: Any, **kwargs: Any) -> dict[str, Any]: async def _iter() -> AsyncIterator[str]: for line in content[Key]: yield line + body = mock.AsyncMock() body.iter_lines = mock.MagicMock() body.iter_lines.return_value = mock.AsyncMock() @@ -50,6 +49,7 @@ async def _iter() -> AsyncIterator[str]: return {"ContentType": "", "Body": body} s3_client.get_object = get_object + return _setup @pytest.fixture @@ -100,6 +100,7 @@ async def test_iterate_log_chunks( def later_iso(sec: int = 0) -> str: return (now + timedelta(seconds=sec)).isoformat() + stored_lines = [] for i, line in enumerate(log_lines): stored_line = {"time": later_iso(i)}