Skip to content

Commit

Permalink
♻️ Fixes flaky test_update_profile and cleanup tests (#3528)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Nov 9, 2022
1 parent 4607b36 commit e7eada1
Show file tree
Hide file tree
Showing 43 changed files with 69 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions packages/pytest-simcore/src/pytest_simcore/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import dotenv
import pytest
from _pytest.monkeypatch import MonkeyPatch
from pytest import MonkeyPatch


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/pytest-simcore/src/pytest_simcore/tmp_path_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion packages/settings-library/tests/test_docker_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions services/agent/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion services/agent/tests/unit/test_modules_volumes_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions services/catalog/tests/unit/test_services_director.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion services/catalog/tests/unit/with_dbs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions services/dask-sidecar/tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion services/dask-sidecar/tests/unit/test_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions services/dask-sidecar/tests/unit/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions services/dask-sidecar/tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
):
Expand All @@ -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,
):
Expand Down
8 changes: 4 additions & 4 deletions services/dask-sidecar/tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
):
Expand Down
2 changes: 1 addition & 1 deletion services/datcore-adapter/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
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
from models_library.projects_nodes import NodeState
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e7eada1

Please sign in to comment.