From e7eada14fa5df39703b026fdff33ef2ec4bb66ea Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 9 Nov 2022 09:34:47 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Fixes=20flaky=20test=5Fupd?= =?UTF-8?q?ate=5Fprofile=20and=20cleanup=20tests=20(#3528)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/test_services_consume_filetypes.py | 3 +-- .../src/pytest_simcore/docker_compose.py | 3 +-- .../src/pytest_simcore/environment_configs.py | 2 +- .../src/pytest_simcore/minio_service.py | 2 +- .../src/pytest_simcore/monkeypatch_extra.py | 3 +-- .../src/pytest_simcore/simcore_services.py | 2 +- .../src/pytest_simcore/tmp_path_extra.py | 3 +-- .../tests/test_docker_registry.py | 2 +- .../test_node_ports_common_r_clone.py | 2 +- services/agent/tests/conftest.py | 3 +-- .../tests/unit/test_modules_volumes_cleanup.py | 2 +- .../tests/unit/test_services_director.py | 6 +++--- .../catalog/tests/unit/with_dbs/conftest.py | 2 +- services/dask-sidecar/tests/unit/conftest.py | 16 ++++++++-------- .../dask-sidecar/tests/unit/test_file_utils.py | 2 +- .../dask-sidecar/tests/unit/test_settings.py | 6 +++--- services/dask-sidecar/tests/unit/test_tasks.py | 17 ++++++++--------- services/dask-sidecar/tests/unit/test_utils.py | 8 ++++---- services/datcore-adapter/tests/unit/conftest.py | 2 +- .../integration/01/test_computation_api.py | 2 +- ..._mixed_dynamic_sidecar_and_legacy_project.py | 2 +- services/director-v2/tests/unit/conftest.py | 3 +-- .../tests/unit/test_modules_dask_client.py | 2 +- .../unit/test_modules_dask_clients_pool.py | 2 +- ...t_modules_dynamic_sidecar_client_api_base.py | 2 +- ...modules_dynamic_sidecar_client_api_public.py | 3 +-- ...t_modules_dynamic_sidecar_client_api_thin.py | 2 +- .../unit/test_modules_dynamic_sidecar_events.py | 3 +-- .../test_modules_dynamic_sidecar_scheduler.py | 2 +- ...st_modules_dynamic_sidecar_scheduler_task.py | 3 +-- .../unit/with_dbs/test_api_route_clusters.py | 2 +- .../with_dbs/test_api_route_clusters_details.py | 2 +- ...est_modules_comp_scheduler_dask_scheduler.py | 2 +- .../test_modules_dynamic_sidecar_docker_api.py | 3 +-- .../tests/unit/with_dbs/test_modules_redis.py | 2 +- .../tests/unit/with_dbs/test_utils_dask.py | 2 +- .../test_api_containers_long_running_tasks.py | 2 +- .../tests/unit/test_core_docker_utils.py | 2 +- services/web/server/tests/conftest.py | 9 ++++++--- .../tests/integration/01/test_exporter.py | 2 +- .../tests/unit/with_dbs/01/clusters/conftest.py | 2 +- .../01/test_resource_manager_redis_registry.py | 2 +- .../web/server/tests/unit/with_dbs/conftest.py | 2 +- 43 files changed, 69 insertions(+), 77 deletions(-) diff --git a/packages/postgres-database/tests/test_services_consume_filetypes.py b/packages/postgres-database/tests/test_services_consume_filetypes.py index f2c1992c44b..bca20e799fc 100644 --- a/packages/postgres-database/tests/test_services_consume_filetypes.py +++ b/packages/postgres-database/tests/test_services_consume_filetypes.py @@ -6,7 +6,6 @@ import pytest import sqlalchemy as sa -from _pytest.fixtures import fixture from aiopg.sa.engine import Engine from aiopg.sa.exc import ResourceClosedError from aiopg.sa.result import ResultProxy, RowProxy @@ -57,7 +56,7 @@ async def _make(conn): return _make -@fixture +@pytest.fixture async def conn(pg_engine: Engine, make_table): async with pg_engine.acquire() as conn: await make_table(conn) diff --git a/packages/pytest-simcore/src/pytest_simcore/docker_compose.py b/packages/pytest-simcore/src/pytest_simcore/docker_compose.py index be449317359..e3213a7697b 100644 --- a/packages/pytest-simcore/src/pytest_simcore/docker_compose.py +++ b/packages/pytest-simcore/src/pytest_simcore/docker_compose.py @@ -20,9 +20,8 @@ import pytest import yaml -from _pytest.config import ExitCode -from _pytest.monkeypatch import MonkeyPatch from dotenv import dotenv_values, set_key +from pytest import ExitCode, MonkeyPatch from .helpers import ( FIXTURE_CONFIG_CORE_SERVICES_SELECTION, diff --git a/packages/pytest-simcore/src/pytest_simcore/environment_configs.py b/packages/pytest-simcore/src/pytest_simcore/environment_configs.py index 987404b93e1..7eb6cefeed3 100644 --- a/packages/pytest-simcore/src/pytest_simcore/environment_configs.py +++ b/packages/pytest-simcore/src/pytest_simcore/environment_configs.py @@ -8,7 +8,7 @@ import dotenv import pytest -from _pytest.monkeypatch import MonkeyPatch +from pytest import MonkeyPatch @pytest.fixture(scope="session") diff --git a/packages/pytest-simcore/src/pytest_simcore/minio_service.py b/packages/pytest-simcore/src/pytest_simcore/minio_service.py index 20d99946ba8..c24c3d639dc 100644 --- a/packages/pytest-simcore/src/pytest_simcore/minio_service.py +++ b/packages/pytest-simcore/src/pytest_simcore/minio_service.py @@ -6,11 +6,11 @@ from typing import Any, Iterator import pytest -from _pytest.monkeypatch import MonkeyPatch from minio import Minio from minio.datatypes import Object from minio.deleteobjects import DeleteError, DeleteObject from pydantic import parse_obj_as +from pytest import MonkeyPatch from tenacity import Retrying from tenacity.before_sleep import before_sleep_log from tenacity.stop import stop_after_attempt diff --git a/packages/pytest-simcore/src/pytest_simcore/monkeypatch_extra.py b/packages/pytest-simcore/src/pytest_simcore/monkeypatch_extra.py index 492fff91643..23cdc565642 100644 --- a/packages/pytest-simcore/src/pytest_simcore/monkeypatch_extra.py +++ b/packages/pytest-simcore/src/pytest_simcore/monkeypatch_extra.py @@ -6,8 +6,7 @@ from typing import Iterator import pytest -from _pytest.fixtures import FixtureRequest -from _pytest.monkeypatch import MonkeyPatch +from pytest import FixtureRequest, MonkeyPatch warnings.warn( f"{__name__} is deprecated, we highly recommend to use pytest.monkeypatch at function-scope level." diff --git a/packages/pytest-simcore/src/pytest_simcore/simcore_services.py b/packages/pytest-simcore/src/pytest_simcore/simcore_services.py index 3338c08baf6..ac6b5d98d05 100644 --- a/packages/pytest-simcore/src/pytest_simcore/simcore_services.py +++ b/packages/pytest-simcore/src/pytest_simcore/simcore_services.py @@ -9,8 +9,8 @@ import aiohttp import pytest -from _pytest.monkeypatch import MonkeyPatch from aiohttp.client import ClientTimeout +from pytest import MonkeyPatch from tenacity._asyncio import AsyncRetrying from tenacity.before_sleep import before_sleep_log from tenacity.stop import stop_after_delay diff --git a/packages/pytest-simcore/src/pytest_simcore/tmp_path_extra.py b/packages/pytest-simcore/src/pytest_simcore/tmp_path_extra.py index c43e0781569..6ab98fccd6a 100644 --- a/packages/pytest-simcore/src/pytest_simcore/tmp_path_extra.py +++ b/packages/pytest-simcore/src/pytest_simcore/tmp_path_extra.py @@ -12,8 +12,7 @@ from pathlib import Path import pytest -from _pytest.fixtures import FixtureRequest -from _pytest.tmpdir import TempPathFactory +from pytest import FixtureRequest, TempPathFactory @pytest.fixture(scope="module") diff --git a/packages/settings-library/tests/test_docker_registry.py b/packages/settings-library/tests/test_docker_registry.py index 27e6f939c40..d168d93cf8a 100644 --- a/packages/settings-library/tests/test_docker_registry.py +++ b/packages/settings-library/tests/test_docker_registry.py @@ -4,7 +4,7 @@ from copy import deepcopy import pytest -from _pytest.monkeypatch import MonkeyPatch +from pytest import MonkeyPatch from settings_library.docker_registry import RegistrySettings MOCKED_BASE_REGISTRY_ENV_VARS: dict[str, str] = { diff --git a/packages/simcore-sdk/tests/integration/test_node_ports_common_r_clone.py b/packages/simcore-sdk/tests/integration/test_node_ports_common_r_clone.py index 9a4de34479a..4c257756cad 100644 --- a/packages/simcore-sdk/tests/integration/test_node_ports_common_r_clone.py +++ b/packages/simcore-sdk/tests/integration/test_node_ports_common_r_clone.py @@ -12,10 +12,10 @@ import aioboto3 import pytest -from _pytest.fixtures import FixtureRequest from faker import Faker from models_library.api_schemas_storage import FileUploadLinks, FileUploadSchema from pydantic import AnyUrl, ByteSize, parse_obj_as +from pytest import FixtureRequest from settings_library.r_clone import RCloneSettings from simcore_sdk.node_ports_common import r_clone diff --git a/services/agent/tests/conftest.py b/services/agent/tests/conftest.py index 86a4ad0efa0..eec19d2221a 100644 --- a/services/agent/tests/conftest.py +++ b/services/agent/tests/conftest.py @@ -9,12 +9,11 @@ import aiodocker import pytest import simcore_service_agent -from _pytest.logging import LogCaptureFixture from aiodocker.volumes import DockerVolume from models_library.basic_types import BootModeEnum from moto.server import ThreadedMotoServer from pydantic import HttpUrl, parse_obj_as -from pytest import MonkeyPatch +from pytest import LogCaptureFixture, MonkeyPatch from pytest_simcore.helpers.utils_docker import get_localhost_ip from settings_library.r_clone import S3Provider from simcore_service_agent.core.settings import ApplicationSettings diff --git a/services/agent/tests/unit/test_modules_volumes_cleanup.py b/services/agent/tests/unit/test_modules_volumes_cleanup.py index 31d4a5f149b..652d28b1f63 100644 --- a/services/agent/tests/unit/test_modules_volumes_cleanup.py +++ b/services/agent/tests/unit/test_modules_volumes_cleanup.py @@ -5,8 +5,8 @@ from pathlib import Path import pytest -from _pytest.logging import LogCaptureFixture from aiodocker.volumes import DockerVolume +from pytest import LogCaptureFixture from pytest_mock.plugin import MockerFixture from simcore_service_agent.core.settings import ApplicationSettings from simcore_service_agent.modules.volumes_cleanup import backup_and_remove_volumes diff --git a/services/catalog/tests/unit/test_services_director.py b/services/catalog/tests/unit/test_services_director.py index 9fda645f0f6..707fe1a6693 100644 --- a/services/catalog/tests/unit/test_services_director.py +++ b/services/catalog/tests/unit/test_services_director.py @@ -5,13 +5,13 @@ # pylint:disable=not-context-manager -from typing import Dict, Iterator +from typing import Iterator import pytest import respx -from _pytest.monkeypatch import MonkeyPatch from fastapi import FastAPI from fastapi.testclient import TestClient +from pytest import MonkeyPatch from respx.router import MockRouter from simcore_service_catalog.api.dependencies.director import get_director_api from simcore_service_catalog.core.application import init_app @@ -20,7 +20,7 @@ @pytest.fixture def minimal_app( - monkeypatch: MonkeyPatch, testing_environ_vars: Dict[str, str] + monkeypatch: MonkeyPatch, testing_environ_vars: dict[str, str] ) -> Iterator[FastAPI]: # disable a couple of subsystems monkeypatch.setenv("CATALOG_POSTGRES", "null") diff --git a/services/catalog/tests/unit/with_dbs/conftest.py b/services/catalog/tests/unit/with_dbs/conftest.py index d96c476fc9e..2099a0ae00f 100644 --- a/services/catalog/tests/unit/with_dbs/conftest.py +++ b/services/catalog/tests/unit/with_dbs/conftest.py @@ -13,11 +13,11 @@ import pytest import respx import sqlalchemy as sa -from _pytest.monkeypatch import MonkeyPatch from faker import Faker from fastapi import FastAPI from models_library.services import ServiceDockerData from models_library.users import UserID +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from simcore_postgres_database.models.products import products from simcore_postgres_database.models.users import UserRole, UserStatus, users diff --git a/services/dask-sidecar/tests/unit/conftest.py b/services/dask-sidecar/tests/unit/conftest.py index 60ab00b75f4..632886b874c 100644 --- a/services/dask-sidecar/tests/unit/conftest.py +++ b/services/dask-sidecar/tests/unit/conftest.py @@ -1,21 +1,21 @@ -# pylint:disable=unused-variable -# pylint:disable=unused-argument -# pylint:disable=redefined-outer-name +# pylint: disable=redefined-outer-name +# pylint: disable=unused-argument +# pylint: disable=unused-variable +# pylint: disable=too-many-arguments from pathlib import Path from pprint import pformat -from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional +from typing import Any, Callable, Iterable, Iterator, Optional import dask import distributed import fsspec import pytest import simcore_service_dask_sidecar -from _pytest.monkeypatch import MonkeyPatch -from _pytest.tmpdir import TempPathFactory from faker import Faker from minio import Minio from pydantic import AnyUrl, parse_obj_as +from pytest import MonkeyPatch, TempPathFactory from pytest_localftpserver.servers import ProcessFTPServer from pytest_mock.plugin import MockerFixture from settings_library.s3 import S3Settings @@ -53,7 +53,7 @@ def installed_package_dir() -> Path: @pytest.fixture() def mock_service_envs( - mock_env_devel_environment: Dict[str, Optional[str]], + mock_env_devel_environment: dict[str, Optional[str]], monkeypatch: MonkeyPatch, mocker: MockerFixture, tmp_path_factory: TempPathFactory, @@ -91,7 +91,7 @@ def dask_client(mock_service_envs: None) -> Iterable[distributed.Client]: @pytest.fixture(scope="module") -def ftp_server(ftpserver: ProcessFTPServer) -> List[URL]: +def ftp_server(ftpserver: ProcessFTPServer) -> list[URL]: faker = Faker() files = ["file_1", "file_2", "file_3"] diff --git a/services/dask-sidecar/tests/unit/test_file_utils.py b/services/dask-sidecar/tests/unit/test_file_utils.py index 28f5fa021d9..8a0512146fd 100644 --- a/services/dask-sidecar/tests/unit/test_file_utils.py +++ b/services/dask-sidecar/tests/unit/test_file_utils.py @@ -12,10 +12,10 @@ import fsspec import pytest -from _pytest.fixtures import FixtureRequest from faker import Faker from minio import Minio from pydantic import AnyUrl, parse_obj_as +from pytest import FixtureRequest from pytest_localftpserver.servers import ProcessFTPServer from pytest_mock.plugin import MockerFixture from settings_library.s3 import S3Settings diff --git a/services/dask-sidecar/tests/unit/test_settings.py b/services/dask-sidecar/tests/unit/test_settings.py index 3037d65969f..8c78e21712a 100644 --- a/services/dask-sidecar/tests/unit/test_settings.py +++ b/services/dask-sidecar/tests/unit/test_settings.py @@ -2,16 +2,16 @@ # pylint: disable=unused-argument # pylint: disable=unused-variable -from typing import Dict, Optional +from typing import Optional import pytest -from _pytest.monkeypatch import MonkeyPatch +from pytest import MonkeyPatch from simcore_service_dask_sidecar.settings import Settings @pytest.fixture def mock_service_envs( - mock_env_devel_environment: Dict[str, Optional[str]], monkeypatch: MonkeyPatch + mock_env_devel_environment: dict[str, Optional[str]], monkeypatch: MonkeyPatch ) -> None: # Variables directly define inside Dockerfile diff --git a/services/dask-sidecar/tests/unit/test_tasks.py b/services/dask-sidecar/tests/unit/test_tasks.py index 35e05c1fece..72a06c1c05a 100644 --- a/services/dask-sidecar/tests/unit/test_tasks.py +++ b/services/dask-sidecar/tests/unit/test_tasks.py @@ -13,14 +13,12 @@ from dataclasses import dataclass from pprint import pformat from random import randint -from typing import Callable, Coroutine, Dict, Iterable, List +from typing import Callable, Coroutine, Iterable from unittest import mock from uuid import uuid4 import fsspec import pytest -from _pytest.fixtures import FixtureRequest -from _pytest.logging import LogCaptureFixture from dask_task_models_library.container_tasks.docker import DockerBasicAuth from dask_task_models_library.container_tasks.events import ( TaskLogEvent, @@ -39,6 +37,7 @@ from models_library.users import UserID from packaging import version from pydantic import AnyUrl, SecretStr +from pytest import FixtureRequest, LogCaptureFixture from pytest_mock.plugin import MockerFixture from settings_library.s3 import S3Settings from simcore_service_dask_sidecar.computational_sidecar.docker_utils import ( @@ -78,7 +77,7 @@ def node_id() -> NodeID: @pytest.fixture() -def dask_subsystem_mock(mocker: MockerFixture) -> Dict[str, MockerFixture]: +def dask_subsystem_mock(mocker: MockerFixture) -> dict[str, MockerFixture]: # mock dask client dask_client_mock = mocker.patch("distributed.Client", autospec=True) @@ -129,12 +128,12 @@ class ServiceExampleParam: docker_basic_auth: DockerBasicAuth service_key: str service_version: str - command: List[str] + command: list[str] input_data: TaskInputData output_data_keys: TaskOutputDataSchema log_file_url: AnyUrl expected_output_data: TaskOutputData - expected_logs: List[str] + expected_logs: list[str] integration_version: version.Version @@ -328,7 +327,7 @@ def test_run_computational_sidecar_real_fct( caplog_info_level: LogCaptureFixture, event_loop: asyncio.AbstractEventLoop, mock_service_envs: None, - dask_subsystem_mock: Dict[str, MockerFixture], + dask_subsystem_mock: dict[str, MockerFixture], ubuntu_task: ServiceExampleParam, mocker: MockerFixture, s3_settings: S3Settings, @@ -500,7 +499,7 @@ def test_failing_service_raises_exception( caplog_info_level: LogCaptureFixture, event_loop: asyncio.AbstractEventLoop, mock_service_envs: None, - dask_subsystem_mock: Dict[str, MockerFixture], + dask_subsystem_mock: dict[str, MockerFixture], ubuntu_task_fail: ServiceExampleParam, s3_settings: S3Settings, ): @@ -521,7 +520,7 @@ def test_running_service_that_generates_unexpected_data_raises_exception( caplog_info_level: LogCaptureFixture, event_loop: asyncio.AbstractEventLoop, mock_service_envs: None, - dask_subsystem_mock: Dict[str, MockerFixture], + dask_subsystem_mock: dict[str, MockerFixture], ubuntu_task_unexpected_output: ServiceExampleParam, s3_settings: S3Settings, ): diff --git a/services/dask-sidecar/tests/unit/test_utils.py b/services/dask-sidecar/tests/unit/test_utils.py index a5c84ad70b2..00f39b39971 100644 --- a/services/dask-sidecar/tests/unit/test_utils.py +++ b/services/dask-sidecar/tests/unit/test_utils.py @@ -4,19 +4,19 @@ import asyncio -from typing import Dict, List, Optional +from typing import Optional from unittest import mock import aiodocker import pytest -from _pytest.monkeypatch import MonkeyPatch +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from simcore_service_dask_sidecar.utils import num_available_gpus @pytest.fixture def mock_service_envs( - mock_env_devel_environment: Dict[str, Optional[str]], monkeypatch: MonkeyPatch + mock_env_devel_environment: dict[str, Optional[str]], monkeypatch: MonkeyPatch ) -> None: monkeypatch.setenv( "SIDECAR_COMP_SERVICES_SHARED_VOLUME_NAME", "simcore_computational_shared_data" @@ -99,7 +99,7 @@ def test_num_available_gpus_returns_0_when_container_wait_timesout( def test_num_available_gpus( event_loop: asyncio.events.AbstractEventLoop, mock_service_envs: None, - container_logs: List[str], + container_logs: list[str], expected_num_gpus: int, mock_aiodocker: mock.MagicMock, ): diff --git a/services/datcore-adapter/tests/unit/conftest.py b/services/datcore-adapter/tests/unit/conftest.py index 686aa6fcfd0..2255753fa2a 100644 --- a/services/datcore-adapter/tests/unit/conftest.py +++ b/services/datcore-adapter/tests/unit/conftest.py @@ -12,9 +12,9 @@ import pytest import respx import simcore_service_datcore_adapter -from _pytest.monkeypatch import MonkeyPatch from asgi_lifespan import LifespanManager from fastapi.applications import FastAPI +from pytest import MonkeyPatch from pytest_mock import MockFixture from simcore_service_datcore_adapter.modules.pennsieve import ( PennsieveAuthorizationHeaders, diff --git a/services/director-v2/tests/integration/01/test_computation_api.py b/services/director-v2/tests/integration/01/test_computation_api.py index e3e9aede05c..2c2ea27b25b 100644 --- a/services/director-v2/tests/integration/01/test_computation_api.py +++ b/services/director-v2/tests/integration/01/test_computation_api.py @@ -15,7 +15,6 @@ import httpx import pytest import sqlalchemy as sa -from _pytest.monkeypatch import MonkeyPatch from httpx import AsyncClient from models_library.clusters import DEFAULT_CLUSTER_ID from models_library.projects import ProjectAtDB @@ -23,6 +22,7 @@ from models_library.projects_nodes_io import NodeID from models_library.projects_pipeline import PipelineDetails from models_library.projects_state import RunningState +from pytest import MonkeyPatch from settings_library.rabbit import RabbitSettings from shared_comp_utils import ( COMPUTATION_URL, diff --git a/services/director-v2/tests/integration/02/test_mixed_dynamic_sidecar_and_legacy_project.py b/services/director-v2/tests/integration/02/test_mixed_dynamic_sidecar_and_legacy_project.py index a743fdaecb2..ceaaf42c155 100644 --- a/services/director-v2/tests/integration/02/test_mixed_dynamic_sidecar_and_legacy_project.py +++ b/services/director-v2/tests/integration/02/test_mixed_dynamic_sidecar_and_legacy_project.py @@ -12,11 +12,11 @@ import httpx import pytest import sqlalchemy as sa -from _pytest.monkeypatch import MonkeyPatch from asgi_lifespan import LifespanManager from faker import Faker from models_library.projects import ProjectAtDB from models_library.services_resources import ServiceResourcesDict +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.utils_docker import get_localhost_ip from settings_library.rabbit import RabbitSettings diff --git a/services/director-v2/tests/unit/conftest.py b/services/director-v2/tests/unit/conftest.py index 64a3fed7a71..7fe0d7445f1 100644 --- a/services/director-v2/tests/unit/conftest.py +++ b/services/director-v2/tests/unit/conftest.py @@ -20,7 +20,6 @@ import respx import traitlets.config from _dask_helpers import DaskGatewayServer -from _pytest.logging import LogCaptureFixture from dask.distributed import Scheduler, Worker from dask_gateway_server.app import DaskGateway from dask_gateway_server.backends.local import UnsafeLocalBackend @@ -33,7 +32,7 @@ from models_library.services import RunID, ServiceKeyVersion from pydantic import parse_obj_as from pydantic.types import NonNegativeInt -from pytest import MonkeyPatch +from pytest import LogCaptureFixture, MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from settings_library.s3 import S3Settings diff --git a/services/director-v2/tests/unit/test_modules_dask_client.py b/services/director-v2/tests/unit/test_modules_dask_client.py index e2389ac8fb1..e06d04a4557 100644 --- a/services/director-v2/tests/unit/test_modules_dask_client.py +++ b/services/director-v2/tests/unit/test_modules_dask_client.py @@ -16,7 +16,6 @@ import pytest import respx from _dask_helpers import DaskGatewayServer -from _pytest.monkeypatch import MonkeyPatch from dask.distributed import get_worker from dask_task_models_library.container_tasks.docker import DockerBasicAuth from dask_task_models_library.container_tasks.errors import TaskCancelledError @@ -42,6 +41,7 @@ from models_library.users import UserID from pydantic import AnyUrl, ByteSize, SecretStr from pydantic.tools import parse_obj_as +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from settings_library.s3 import S3Settings diff --git a/services/director-v2/tests/unit/test_modules_dask_clients_pool.py b/services/director-v2/tests/unit/test_modules_dask_clients_pool.py index c141d7f6f9d..a548ee5260e 100644 --- a/services/director-v2/tests/unit/test_modules_dask_clients_pool.py +++ b/services/director-v2/tests/unit/test_modules_dask_clients_pool.py @@ -9,7 +9,6 @@ import pytest from _dask_helpers import DaskGatewayServer -from _pytest.monkeypatch import MonkeyPatch from distributed.deploy.spec import SpecCluster from faker import Faker from models_library.clusters import ( @@ -22,6 +21,7 @@ SimpleAuthentication, ) from pydantic import SecretStr +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from settings_library.utils_cli import create_json_encoder_wo_secrets diff --git a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_base.py b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_base.py index 7ba4334c4cf..35b53e7f23e 100644 --- a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_base.py +++ b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_base.py @@ -1,7 +1,6 @@ # pylint:disable=redefined-outer-name import pytest -from _pytest.logging import LogCaptureFixture from httpx import ( ConnectError, HTTPError, @@ -12,6 +11,7 @@ codes, ) from pydantic import AnyHttpUrl, parse_obj_as +from pytest import LogCaptureFixture from respx import MockRouter from simcore_service_director_v2.modules.dynamic_sidecar.api_client._base import ( BaseThinClient, diff --git a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_public.py b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_public.py index ed58a3affc7..a9f8636b9b6 100644 --- a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_public.py +++ b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_public.py @@ -6,11 +6,10 @@ from unittest.mock import AsyncMock import pytest -from _pytest.logging import LogCaptureFixture -from _pytest.monkeypatch import MonkeyPatch from fastapi import FastAPI, status from httpx import HTTPError, Response from pydantic import AnyHttpUrl, parse_obj_as +from pytest import LogCaptureFixture, MonkeyPatch from pytest_mock import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_service_director_v2.core.settings import AppSettings diff --git a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_thin.py b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_thin.py index 9296cafce9c..99a615dc89f 100644 --- a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_thin.py +++ b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_thin.py @@ -5,10 +5,10 @@ from typing import Any, Callable, Optional import pytest -from _pytest.monkeypatch import MonkeyPatch from fastapi import FastAPI, status from httpx import Response from pydantic import AnyHttpUrl, parse_obj_as +from pytest import MonkeyPatch from pytest_simcore.helpers.typing_env import EnvVarsDict from respx import MockRouter, Route from respx.types import SideEffectTypes diff --git a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_events.py b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_events.py index b8d2c2ce2e5..5299bfa58fc 100644 --- a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_events.py +++ b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_events.py @@ -5,10 +5,9 @@ from typing import Final import pytest -from _pytest.logging import LogCaptureFixture -from _pytest.monkeypatch import MonkeyPatch from fastapi import FastAPI from pydantic import PositiveFloat, PositiveInt +from pytest import LogCaptureFixture, MonkeyPatch from pytest_mock import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from pytest_simcore.helpers.utils_envs import setenvs_from_dict diff --git a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler.py b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler.py index 1c284562865..ed5d05aec30 100644 --- a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler.py +++ b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler.py @@ -13,9 +13,9 @@ import httpx import pytest import respx -from _pytest.monkeypatch import MonkeyPatch from fastapi import FastAPI from models_library.service_settings_labels import SimcoreServiceLabels +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from respx.router import MockRouter diff --git a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler_task.py b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler_task.py index 1b94cab78ae..e3d76e7d261 100644 --- a/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler_task.py +++ b/services/director-v2/tests/unit/test_modules_dynamic_sidecar_scheduler_task.py @@ -10,9 +10,8 @@ import httpx import pytest import respx -from _pytest.monkeypatch import MonkeyPatch from fastapi import FastAPI -from pytest import FixtureRequest +from pytest import FixtureRequest, MonkeyPatch from pytest_mock import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from pytest_simcore.helpers.utils_envs import setenvs_from_dict diff --git a/services/director-v2/tests/unit/with_dbs/test_api_route_clusters.py b/services/director-v2/tests/unit/with_dbs/test_api_route_clusters.py index bd8f7786bf0..48703324a3a 100644 --- a/services/director-v2/tests/unit/with_dbs/test_api_route_clusters.py +++ b/services/director-v2/tests/unit/with_dbs/test_api_route_clusters.py @@ -10,7 +10,6 @@ import pytest import sqlalchemy as sa from _dask_helpers import DaskGatewayServer -from _pytest.monkeypatch import MonkeyPatch from distributed.deploy.spec import SpecCluster from faker import Faker from httpx import URL @@ -25,6 +24,7 @@ SimpleAuthentication, ) from pydantic import AnyHttpUrl, SecretStr, parse_obj_as +from pytest import MonkeyPatch from pytest_simcore.helpers.typing_env import EnvVarsDict from settings_library.utils_cli import create_json_encoder_wo_secrets from simcore_postgres_database.models.clusters import ClusterType, clusters diff --git a/services/director-v2/tests/unit/with_dbs/test_api_route_clusters_details.py b/services/director-v2/tests/unit/with_dbs/test_api_route_clusters_details.py index e5a8d408dfe..de9c7aed640 100644 --- a/services/director-v2/tests/unit/with_dbs/test_api_route_clusters_details.py +++ b/services/director-v2/tests/unit/with_dbs/test_api_route_clusters_details.py @@ -9,7 +9,6 @@ import pytest import sqlalchemy as sa from _dask_helpers import DaskGatewayServer -from _pytest.monkeypatch import MonkeyPatch from dask_gateway import Gateway, GatewayCluster, auth from distributed import Client as DaskClient from distributed.deploy.spec import SpecCluster @@ -17,6 +16,7 @@ from models_library.clusters import Cluster, ClusterID, SimpleAuthentication from models_library.users import UserID from pydantic import SecretStr +from pytest import MonkeyPatch from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_service_director_v2.models.schemas.clusters import ClusterDetailsGet from starlette import status diff --git a/services/director-v2/tests/unit/with_dbs/test_modules_comp_scheduler_dask_scheduler.py b/services/director-v2/tests/unit/with_dbs/test_modules_comp_scheduler_dask_scheduler.py index 6d1d6c0bc9d..e1cecaeb849 100644 --- a/services/director-v2/tests/unit/with_dbs/test_modules_comp_scheduler_dask_scheduler.py +++ b/services/director-v2/tests/unit/with_dbs/test_modules_comp_scheduler_dask_scheduler.py @@ -23,7 +23,6 @@ manually_run_comp_scheduler, set_comp_task_state, ) -from _pytest.monkeypatch import MonkeyPatch from dask.distributed import SpecCluster from dask_task_models_library.container_tasks.errors import TaskCancelledError from dask_task_models_library.container_tasks.io import TaskOutputData @@ -31,6 +30,7 @@ from models_library.clusters import DEFAULT_CLUSTER_ID from models_library.projects import ProjectAtDB from models_library.projects_state import RunningState +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_postgres_database.models.comp_pipeline import StateType diff --git a/services/director-v2/tests/unit/with_dbs/test_modules_dynamic_sidecar_docker_api.py b/services/director-v2/tests/unit/with_dbs/test_modules_dynamic_sidecar_docker_api.py index 0fbb60ab881..3ce701620da 100644 --- a/services/director-v2/tests/unit/with_dbs/test_modules_dynamic_sidecar_docker_api.py +++ b/services/director-v2/tests/unit/with_dbs/test_modules_dynamic_sidecar_docker_api.py @@ -11,7 +11,6 @@ import aiodocker import pytest -from _pytest.monkeypatch import MonkeyPatch from aiodocker.utils import clean_filters from aiodocker.volumes import DockerVolume from faker import Faker @@ -19,7 +18,7 @@ from models_library.projects import ProjectID from models_library.projects_nodes_io import NodeID from models_library.users import UserID -from pytest import FixtureRequest +from pytest import FixtureRequest, MonkeyPatch from pytest_simcore.helpers.utils_envs import EnvVarsDict from simcore_service_director_v2.core.settings import DynamicSidecarSettings from simcore_service_director_v2.models.schemas.constants import ( diff --git a/services/director-v2/tests/unit/with_dbs/test_modules_redis.py b/services/director-v2/tests/unit/with_dbs/test_modules_redis.py index e177cdc9686..7cde0c7ce9c 100644 --- a/services/director-v2/tests/unit/with_dbs/test_modules_redis.py +++ b/services/director-v2/tests/unit/with_dbs/test_modules_redis.py @@ -8,11 +8,11 @@ from typing import Any, AsyncIterable, Final import pytest -from _pytest.monkeypatch import MonkeyPatch from asgi_lifespan import LifespanManager from faker import Faker from fastapi import FastAPI from pydantic import PositiveFloat +from pytest import MonkeyPatch from redis.exceptions import LockError, LockNotOwnedError from settings_library.redis import RedisSettings from simcore_service_director_v2.core.errors import NodeRightsAcquireError diff --git a/services/director-v2/tests/unit/with_dbs/test_utils_dask.py b/services/director-v2/tests/unit/with_dbs/test_utils_dask.py index 49f4c3dbcd6..743243b3ebc 100644 --- a/services/director-v2/tests/unit/with_dbs/test_utils_dask.py +++ b/services/director-v2/tests/unit/with_dbs/test_utils_dask.py @@ -15,7 +15,6 @@ import httpx import pytest from _helpers import PublishedProject, set_comp_task_inputs, set_comp_task_outputs -from _pytest.monkeypatch import MonkeyPatch from dask_task_models_library.container_tasks.io import ( FilePortSchema, FileUrl, @@ -29,6 +28,7 @@ from pydantic import ByteSize from pydantic.networks import AnyUrl from pydantic.tools import parse_obj_as +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_sdk.node_ports_v2 import FileLinkType diff --git a/services/dynamic-sidecar/tests/unit/test_api_containers_long_running_tasks.py b/services/dynamic-sidecar/tests/unit/test_api_containers_long_running_tasks.py index 7b741be2c93..6e50f375eec 100644 --- a/services/dynamic-sidecar/tests/unit/test_api_containers_long_running_tasks.py +++ b/services/dynamic-sidecar/tests/unit/test_api_containers_long_running_tasks.py @@ -20,7 +20,6 @@ import aiodocker import faker import pytest -from _pytest.fixtures import FixtureRequest from aiodocker.containers import DockerContainer from aiodocker.volumes import DockerVolume from asgi_lifespan import LifespanManager @@ -28,6 +27,7 @@ from fastapi.routing import APIRoute from httpx import AsyncClient from pydantic import AnyHttpUrl, parse_obj_as +from pytest import FixtureRequest from pytest_mock.plugin import MockerFixture from servicelib.fastapi.long_running_tasks.client import ( Client, diff --git a/services/dynamic-sidecar/tests/unit/test_core_docker_utils.py b/services/dynamic-sidecar/tests/unit/test_core_docker_utils.py index 12d4dacb2c3..baaabfc41b4 100644 --- a/services/dynamic-sidecar/tests/unit/test_core_docker_utils.py +++ b/services/dynamic-sidecar/tests/unit/test_core_docker_utils.py @@ -5,10 +5,10 @@ import aiodocker import pytest -from _pytest.fixtures import FixtureRequest from faker import Faker from models_library.services import RunID from pydantic import PositiveInt +from pytest import FixtureRequest from simcore_service_dynamic_sidecar.core.docker_utils import ( get_running_containers_count_from_names, get_volume_by_label, diff --git a/services/web/server/tests/conftest.py b/services/web/server/tests/conftest.py index fdeeb486a3f..2c66a979041 100644 --- a/services/web/server/tests/conftest.py +++ b/services/web/server/tests/conftest.py @@ -13,11 +13,12 @@ import pytest import simcore_service_webserver -from _pytest.monkeypatch import MonkeyPatch from aiohttp import web from aiohttp.test_utils import TestClient from models_library.projects_networks import PROJECT_NETWORK_PREFIX from models_library.projects_state import ProjectState +from pytest import MonkeyPatch +from pytest_mock import MockerFixture from pytest_simcore.helpers.utils_assert import assert_status from pytest_simcore.helpers.utils_dict import ConfigDict from pytest_simcore.helpers.utils_login import LoggedUser, UserInfoDict @@ -115,7 +116,9 @@ def fake_project(tests_data_dir: Path) -> ProjectDict: @pytest.fixture() -async def logged_user(client, user_role: UserRole) -> AsyncIterator[UserInfoDict]: +async def logged_user( + client: TestClient, user_role: UserRole +) -> AsyncIterator[UserInfoDict]: """adds a user in db and logs in with client NOTE: `user_role` fixture is defined as a parametrization below!!! @@ -157,7 +160,7 @@ def _patch(app_config: dict) -> dict[str, str]: @pytest.fixture -def mock_projects_networks_network_name(mocker) -> None: +def mock_projects_networks_network_name(mocker: MockerFixture) -> None: remove_orphaned_services = mocker.patch( "simcore_service_webserver.projects_networks._network_name", return_value=f"{PROJECT_NETWORK_PREFIX}_{UUID(int=0)}_mocked", diff --git a/services/web/server/tests/integration/01/test_exporter.py b/services/web/server/tests/integration/01/test_exporter.py index c0d57c08806..df5532361bd 100644 --- a/services/web/server/tests/integration/01/test_exporter.py +++ b/services/web/server/tests/integration/01/test_exporter.py @@ -25,12 +25,12 @@ import aiopg.sa import pytest import redis.asyncio as aioredis -from _pytest.monkeypatch import MonkeyPatch from aiohttp.test_utils import TestClient from models_library.api_schemas_storage import LinkType from models_library.projects_nodes_io import LocationID, StorageFileID from models_library.users import UserID from pydantic import AnyUrl, parse_obj_as +from pytest import MonkeyPatch from pytest_simcore.docker_registry import _pull_push_service from pytest_simcore.helpers.utils_login import log_client_in from servicelib.aiohttp.application import create_safe_application diff --git a/services/web/server/tests/unit/with_dbs/01/clusters/conftest.py b/services/web/server/tests/unit/with_dbs/01/clusters/conftest.py index e1a8a7cde77..42fa15136cc 100644 --- a/services/web/server/tests/unit/with_dbs/01/clusters/conftest.py +++ b/services/web/server/tests/unit/with_dbs/01/clusters/conftest.py @@ -1,5 +1,5 @@ import pytest -from _pytest.monkeypatch import MonkeyPatch +from pytest import MonkeyPatch @pytest.fixture diff --git a/services/web/server/tests/unit/with_dbs/01/test_resource_manager_redis_registry.py b/services/web/server/tests/unit/with_dbs/01/test_resource_manager_redis_registry.py index bf9cb091f54..4c2f77dfeb8 100644 --- a/services/web/server/tests/unit/with_dbs/01/test_resource_manager_redis_registry.py +++ b/services/web/server/tests/unit/with_dbs/01/test_resource_manager_redis_registry.py @@ -8,8 +8,8 @@ import pytest import redis.asyncio as aioredis -from _pytest.monkeypatch import MonkeyPatch from aiohttp import web +from pytest import MonkeyPatch from servicelib.aiohttp.application import create_safe_application from servicelib.aiohttp.application_setup import is_setup_completed from simcore_service_webserver.application_settings import setup_settings diff --git a/services/web/server/tests/unit/with_dbs/conftest.py b/services/web/server/tests/unit/with_dbs/conftest.py index ba40eee428b..deec6692a33 100644 --- a/services/web/server/tests/unit/with_dbs/conftest.py +++ b/services/web/server/tests/unit/with_dbs/conftest.py @@ -26,10 +26,10 @@ import simcore_service_webserver.utils import sqlalchemy as sa from _helpers import MockedStorageSubsystem -from _pytest.monkeypatch import MonkeyPatch from aiohttp import web from aiohttp.test_utils import TestClient, TestServer from pydantic import ByteSize, parse_obj_as +from pytest import MonkeyPatch from pytest_mock.plugin import MockerFixture from pytest_simcore.helpers.utils_dict import ConfigDict from pytest_simcore.helpers.utils_login import NewUser