diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 07640edc..fd18452f 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -75,7 +75,7 @@ def minikube_ip() -> str: return subprocess.check_output(("minikube", "ip"), text=True).strip() -@pytest.fixture() +@pytest.fixture async def client() -> AsyncIterator[aiohttp.ClientSession]: async with aiohttp.ClientSession() as session: yield session @@ -105,7 +105,7 @@ async def wait_for_service( await asyncio.sleep(interval_s) -@pytest.fixture() +@pytest.fixture # TODO (A Yushkovskiy, 05-May-2019) This fixture should have scope="session" in order # to be faster, but it causes mysterious errors `RuntimeError: Event loop is closed` async def platform_api_config( @@ -126,7 +126,7 @@ async def platform_api_config( ) -@pytest.fixture() +@pytest.fixture async def container_runtime_config(in_minikube: bool) -> ContainerRuntimeConfig: # noqa: FBT001 if in_minikube: url = URL("http://platform-container-runtime:9000") @@ -140,7 +140,7 @@ async def container_runtime_config(in_minikube: bool) -> ContainerRuntimeConfig: return ContainerRuntimeConfig(port=url.port) -@pytest.fixture() +@pytest.fixture async def container_runtime_client_registry( container_runtime_config: ContainerRuntimeConfig, ) -> AsyncIterator[ContainerRuntimeClientRegistry]: @@ -150,7 +150,7 @@ async def container_runtime_client_registry( yield registry -@pytest.fixture() +@pytest.fixture # TODO (A Yushkovskiy, 05-May-2019) This fixture should have scope="session" in order # to be faster, but it causes mysterious errors `RuntimeError: Event loop is closed` async def es_config( @@ -173,7 +173,7 @@ async def es_config( return ElasticsearchConfig(hosts=[es_host]) -@pytest.fixture() +@pytest.fixture async def es_client( es_config: ElasticsearchConfig, ) -> AsyncIterator[AsyncElasticsearch]: @@ -184,7 +184,7 @@ async def es_client( yield es_client -@pytest.fixture() +@pytest.fixture def s3_config() -> S3Config: s3_url = get_service_url(service_name="minio") return S3Config( @@ -196,13 +196,13 @@ def s3_config() -> S3Config: ) -@pytest.fixture() +@pytest.fixture async def s3_client(s3_config: S3Config) -> AsyncIterator[AioBaseClient]: async with create_s3_client(s3_config) as client: yield client -@pytest.fixture() +@pytest.fixture async def s3_logs_bucket(s3_config: S3Config, s3_client: AioBaseClient) -> str: try: await s3_client.create_bucket(Bucket=s3_config.job_logs_bucket_name) @@ -212,7 +212,7 @@ async def s3_logs_bucket(s3_config: S3Config, s3_client: AioBaseClient) -> str: return s3_config.job_logs_bucket_name -@pytest.fixture() +@pytest.fixture async def registry_config(request: FixtureRequest, in_minikube: bool) -> RegistryConfig: # noqa: FBT001 if in_minikube: external_url = URL("http://registry.kube-system") @@ -224,7 +224,7 @@ async def registry_config(request: FixtureRequest, in_minikube: bool) -> Registr return RegistryConfig(URL("http://localhost:5000")) -@pytest.fixture() +@pytest.fixture def config_factory( auth_config: PlatformAuthConfig, platform_api_config: PlatformApiConfig, @@ -256,12 +256,12 @@ def _f(**kwargs: Any) -> Config: return _f -@pytest.fixture() +@pytest.fixture def config(config_factory: Callable[..., Config]) -> Config: return config_factory() -@pytest.fixture() +@pytest.fixture def config_s3_storage( config_factory: Callable[..., Config], s3_config: S3Config ) -> Config: diff --git a/tests/integration/conftest_auth.py b/tests/integration/conftest_auth.py index eb72f34b..e5962bff 100644 --- a/tests/integration/conftest_auth.py +++ b/tests/integration/conftest_auth.py @@ -45,7 +45,7 @@ def auth_config( ) -@pytest.fixture() +@pytest.fixture async def auth_client( auth_config: PlatformAuthConfig, ) -> AsyncGenerator[AuthClient, None]: @@ -63,7 +63,7 @@ def headers(self) -> dict[str, str]: return {AUTHORIZATION: f"Bearer {self.token}"} -@pytest.fixture() +@pytest.fixture async def share_job( auth_client: AuthClient, cluster_name: str ) -> Callable[[_User, _User, str, str], Awaitable[None]]: diff --git a/tests/integration/conftest_config.py b/tests/integration/conftest_config.py index 1f028c60..a0a466e9 100644 --- a/tests/integration/conftest_config.py +++ b/tests/integration/conftest_config.py @@ -20,7 +20,7 @@ def cluster_token(token_factory: Callable[[str], str]) -> str: return token_factory("cluster") -@pytest.fixture() +@pytest.fixture async def platform_config_url( platform_api_config: PlatformApiConfig, in_minikube: bool, # noqa: FBT001 @@ -31,14 +31,14 @@ async def platform_config_url( return URL(get_service_url("platformconfig", namespace="default")) -@pytest.fixture() +@pytest.fixture def platform_config( platform_config_url: URL, token_factory: Callable[[str], str] ) -> PlatformConfig: return PlatformConfig(url=platform_config_url, token=token_factory("cluster")) -@pytest.fixture() +@pytest.fixture async def platform_config_client( platform_config_url: URL, cluster_token: str ) -> AsyncIterator[ConfigClient]: diff --git a/tests/integration/conftest_kube.py b/tests/integration/conftest_kube.py index d05ece7f..71967c9b 100644 --- a/tests/integration/conftest_kube.py +++ b/tests/integration/conftest_kube.py @@ -192,7 +192,7 @@ def cert_authority_data_pem(kube_config_cluster_payload: dict[str, Any]) -> str return None -@pytest.fixture() +@pytest.fixture async def kube_config(request: FixtureRequest, in_minikube: bool) -> KubeConfig: # noqa: FBT001 if in_minikube: return KubeConfig( @@ -218,7 +218,7 @@ async def kube_config(request: FixtureRequest, in_minikube: bool) -> KubeConfig: ) -@pytest.fixture() +@pytest.fixture async def kube_client(kube_config: KubeConfig) -> AsyncIterator[MyKubeClient]: # TODO (A Danshyn 06/06/18): create a factory method client = MyKubeClient( @@ -239,20 +239,20 @@ async def kube_client(kube_config: KubeConfig) -> AsyncIterator[MyKubeClient]: yield client -@pytest.fixture() +@pytest.fixture async def _kube_node(kube_client: KubeClient) -> Node: nodes = await kube_client.get_nodes() assert len(nodes) == 1, "Should be exactly one minikube node" return nodes[0] -@pytest.fixture() +@pytest.fixture async def kube_node_name(_kube_node: Node) -> str: assert _kube_node.metadata.name return _kube_node.metadata.name -@pytest.fixture() +@pytest.fixture async def kube_container_runtime(_kube_node: Node) -> str: version = _kube_node.status.node_info.container_runtime_version end = version.find("://") diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 298408f5..bcc3ea6a 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -168,14 +168,14 @@ def generate_job_url(self, job_id: str) -> URL: return self.jobs_base_url / job_id -@pytest.fixture() +@pytest.fixture async def monitoring_api(config: Config) -> AsyncIterator[MonitoringApiEndpoints]: app = await create_app(config) async with create_local_app_server(app, port=8080) as address: yield MonitoringApiEndpoints(address=address) -@pytest.fixture() +@pytest.fixture async def monitoring_api_s3_storage( config_s3_storage: Config, ) -> AsyncIterator[MonitoringApiEndpoints]: @@ -184,7 +184,7 @@ async def monitoring_api_s3_storage( yield MonitoringApiEndpoints(address=address) -@pytest.fixture() +@pytest.fixture def platform_api( platform_api_config: PlatformApiConfig, ) -> PlatformApiEndpoints: @@ -282,7 +282,7 @@ async def drop_job(self, job_id: str, *, assert_success: bool = True) -> None: assert response.status == HTTPNoContent.status_code -@pytest.fixture() +@pytest.fixture def jobs_client_factory( platform_api: PlatformApiEndpoints, client: aiohttp.ClientSession ) -> Callable[[_User], JobsClient]: @@ -292,7 +292,7 @@ def impl(user: _User) -> JobsClient: return impl -@pytest.fixture() +@pytest.fixture async def jobs_client( regular_user1: _User, jobs_client_factory: Callable[[_User], JobsClient], @@ -300,7 +300,7 @@ async def jobs_client( return jobs_client_factory(regular_user1) -@pytest.fixture() +@pytest.fixture def job_request_factory() -> Callable[[], dict[str, Any]]: def _factory() -> dict[str, Any]: return { @@ -314,14 +314,14 @@ def _factory() -> dict[str, Any]: return _factory -@pytest.fixture() +@pytest.fixture async def job_submit( job_request_factory: Callable[[], dict[str, Any]], ) -> dict[str, Any]: return job_request_factory() -@pytest.fixture() +@pytest.fixture async def job_factory( jobs_client: JobsClient, job_request_factory: Callable[[], dict[str, Any]], @@ -350,17 +350,17 @@ async def _f(command: str, name: str = "") -> str: await jobs_client.wait_job_dematerialized(job_id) -@pytest.fixture() +@pytest.fixture async def infinite_job(job_factory: Callable[[str], Awaitable[str]]) -> str: return await job_factory("tail -f /dev/null") -@pytest.fixture() +@pytest.fixture def job_name() -> str: return f"test-job-{random_str()}" -@pytest.fixture() +@pytest.fixture async def named_infinite_job( job_factory: Callable[[str, str], Awaitable[str]], job_name: str ) -> str: @@ -1366,7 +1366,7 @@ async def test_port_forward_cannot_connect( async with client.get(url, headers=headers) as response: assert response.status == HTTPBadRequest.status_code, await response.text() - @pytest.mark.minikube() + @pytest.mark.minikube async def test_port_forward_ok( self, monitoring_api: MonitoringApiEndpoints, diff --git a/tests/integration/test_jobs_service.py b/tests/integration/test_jobs_service.py index e028191f..e23438f3 100644 --- a/tests/integration/test_jobs_service.py +++ b/tests/integration/test_jobs_service.py @@ -31,7 +31,7 @@ JobFactory = Callable[..., Awaitable[Job]] -@pytest.fixture() +@pytest.fixture async def job_factory( platform_api_client: PlatformApiClient, ) -> AsyncIterator[JobFactory]: @@ -59,19 +59,19 @@ async def _factory( @pytest.mark.usefixtures("cluster_name") class TestJobsService: - @pytest.fixture() + @pytest.fixture def user(self, regular_user1: _User) -> User: return User(name=regular_user1.name, token=regular_user1.token) - @pytest.fixture() + @pytest.fixture def registry_host(self) -> str: return "localhost:5000" - @pytest.fixture() + @pytest.fixture def image_tag(self) -> str: return str(uuid.uuid4())[:8] - @pytest.fixture() + @pytest.fixture async def platform_api_client( self, platform_api_config: PlatformApiConfig, user: User ) -> AsyncIterator[PlatformApiClient]: @@ -80,7 +80,7 @@ async def platform_api_client( ) as client: yield client - @pytest.fixture() + @pytest.fixture async def jobs_service( self, platform_config_client: ConfigClient, diff --git a/tests/integration/test_kube.py b/tests/integration/test_kube.py index 419d951f..e49eaab1 100644 --- a/tests/integration/test_kube.py +++ b/tests/integration/test_kube.py @@ -68,12 +68,12 @@ logger = logging.getLogger(__name__) -@pytest.fixture() +@pytest.fixture def job_pod() -> MyPodDescriptor: return MyPodDescriptor(f"job-{uuid4()}") -@pytest.fixture() +@pytest.fixture async def mock_kubernetes_server() -> AsyncIterator[ApiAddress]: async def _get_pod(request: web.Request) -> web.Response: payload: dict[str, Any] = { @@ -128,21 +128,21 @@ def _create_app() -> web.Application: yield address -@pytest.fixture() +@pytest.fixture def elasticsearch_log_service( kube_client: MyKubeClient, es_client: AsyncElasticsearch ) -> ElasticsearchLogsService: return ElasticsearchLogsService(kube_client, es_client) -@pytest.fixture() +@pytest.fixture def s3_logs_metadata_storage( s3_client: AioBaseClient, s3_logs_bucket: str ) -> S3LogsMetadataStorage: return S3LogsMetadataStorage(s3_client, s3_logs_bucket) -@pytest.fixture() +@pytest.fixture def s3_logs_metadata_service( s3_client: AioBaseClient, s3_logs_metadata_storage: S3LogsMetadataStorage, @@ -153,7 +153,7 @@ def s3_logs_metadata_service( ) -@pytest.fixture() +@pytest.fixture def s3_log_service( kube_client: MyKubeClient, s3_client: AioBaseClient, @@ -166,7 +166,7 @@ def s3_log_service( class TestKubeClientTokenUpdater: - @pytest.fixture() + @pytest.fixture async def kube_app(self) -> aiohttp.web.Application: async def _get_nodes(request: aiohttp.web.Request) -> aiohttp.web.Response: auth = request.headers["Authorization"] @@ -179,7 +179,7 @@ async def _get_nodes(request: aiohttp.web.Request) -> aiohttp.web.Response: app.router.add_routes([aiohttp.web.get("/api/v1/nodes", _get_nodes)]) return app - @pytest.fixture() + @pytest.fixture async def kube_server( self, kube_app: aiohttp.web.Application, unused_tcp_port_factory: Any ) -> AsyncIterator[str]: @@ -188,14 +188,14 @@ async def kube_server( ) as address: yield f"http://{address.host}:{address.port}" - @pytest.fixture() + @pytest.fixture def kube_token_path(self) -> Iterator[str]: _, path = tempfile.mkstemp() Path(path).write_text("token-1") yield path Path(path).unlink() - @pytest.fixture() + @pytest.fixture async def kube_client( self, kube_server: str, kube_token_path: str ) -> AsyncIterator[KubeClient]: @@ -533,7 +533,7 @@ async def test_create_log_stream_not_found(self, kube_client: KubeClient) -> Non ): pass - @pytest.mark.xfail() + @pytest.mark.xfail async def test_create_log_stream_creating( self, kube_client: MyKubeClient, job_pod: MyPodDescriptor ) -> None: @@ -1640,7 +1640,7 @@ async def test_s3_log_reader_terminated_pod_compacted( ) -@pytest.fixture() +@pytest.fixture async def write_lines_to_s3( s3_client: AioBaseClient, s3_logs_bucket: str ) -> Callable[..., Awaitable[None]]: @@ -2080,7 +2080,7 @@ async def test_add_pod_to_cleanup_queue__recent_logs( class TestS3LogRecordReader: - @pytest.fixture() + @pytest.fixture def reader( self, s3_client: AioBaseClient, s3_logs_bucket: str ) -> S3LogRecordsReader: @@ -2220,7 +2220,7 @@ async def test_iter_records__fallback_to_last_record_time( class TestS3LogRecordWriter: - @pytest.fixture() + @pytest.fixture def records(self) -> list[S3LogRecord]: return [ S3LogRecord( @@ -2367,7 +2367,7 @@ async def test_write__shared_buffer( class TestS3LogsService: - @pytest.fixture() + @pytest.fixture def assert_records_written( self, s3_client: AioBaseClient, s3_logs_bucket: str ) -> Callable[..., Awaitable[None]]: diff --git a/tests/integration/test_log_compact.py b/tests/integration/test_log_compact.py index 593c456e..a4285c31 100644 --- a/tests/integration/test_log_compact.py +++ b/tests/integration/test_log_compact.py @@ -30,7 +30,7 @@ async def compact_all( raise Exception(msg) -@pytest.fixture() +@pytest.fixture def config(config: Config) -> Config: return replace( config, diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index c2e5202c..94856f48 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -18,12 +18,12 @@ from platform_monitoring.logs import ElasticsearchLogsService, S3LogsService -@pytest.fixture() +@pytest.fixture def kube_client() -> mock.Mock: return mock.Mock(spec=KubeClient) -@pytest.fixture() +@pytest.fixture def config_factory() -> Callable[[LogsStorageType], Config]: def _factory(storage_type: LogsStorageType) -> Config: return Config( diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 3d12ad71..abb4a333 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -27,21 +27,21 @@ TOKEN = "this-is-token" -@pytest.fixture() +@pytest.fixture def cert_authority_path(tmp_path: Path) -> str: ca_path = tmp_path / "ca.crt" ca_path.write_text(CA_DATA_PEM) return str(ca_path) -@pytest.fixture() +@pytest.fixture def token_path(tmp_path: Path) -> str: token_path = tmp_path / "token" token_path.write_text(TOKEN) return str(token_path) -@pytest.fixture() +@pytest.fixture def environ(cert_authority_path: str, token_path: str) -> dict[str, Any]: return { "NP_MONITORING_CLUSTER_NAME": "default", diff --git a/tests/unit/test_jobs_service.py b/tests/unit/test_jobs_service.py index 44188db9..3c2b86ea 100644 --- a/tests/unit/test_jobs_service.py +++ b/tests/unit/test_jobs_service.py @@ -97,7 +97,7 @@ def create_pod( return Pod.from_primitive(payload) -@pytest.fixture() +@pytest.fixture def cluster() -> Cluster: return Cluster( name="default", @@ -164,19 +164,19 @@ async def get_cluster(name: str) -> Cluster: return get_cluster -@pytest.fixture() +@pytest.fixture def config_client(cluster: Cluster) -> mock.Mock: client = mock.Mock(spec=ConfigClient) client.get_cluster.side_effect = get_cluster_factory(cluster) return client -@pytest.fixture() +@pytest.fixture def jobs_client() -> mock.Mock: return mock.Mock(spec=JobsClient) -@pytest.fixture() +@pytest.fixture def kube_client() -> mock.Mock: async def get_nodes(label_selector: str = "") -> Sequence[Node]: assert label_selector == "platform.neuromation.io/nodepool" @@ -207,7 +207,7 @@ async def get_nodes(label_selector: str = "") -> Sequence[Node]: return client -@pytest.fixture() +@pytest.fixture def service( config_client: ConfigClient, jobs_client: JobsClient, kube_client: KubeClient ) -> JobsService: