Skip to content

Commit d672a86

Browse files
committed
fixed v2 test
1 parent 133e8ec commit d672a86

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

tests/test_api/test_tasks.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# License: BSD 3-Clause
22
from __future__ import annotations
33

4+
from openml._api.config import settings
45
import pytest
56
import pandas as pd
6-
import requests
7+
from openml._api.clients.http import HTTPClient
78
from openml.testing import TestBase
8-
from openml._api import api_context
99
from openml._api.resources.tasks import TasksV1, TasksV2
1010
from openml.tasks.task import (
1111
OpenMLClassificationTask,
@@ -17,8 +17,26 @@
1717
class TestTasksEndpoints(TestBase):
1818
def setUp(self):
1919
super().setUp()
20-
self.v1_api = TasksV1(api_context.backend.tasks._http)
21-
self.v2_api = TasksV2(api_context.backend.tasks._http)
20+
v1_http_client = HTTPClient(
21+
server=settings.api.v1.server,
22+
base_url=settings.api.v1.base_url,
23+
api_key=settings.api.v1.api_key,
24+
timeout=settings.api.v1.timeout,
25+
retries=settings.connection.retries,
26+
delay_method=settings.connection.delay_method,
27+
delay_time=settings.connection.delay_time,
28+
)
29+
v2_http_client = HTTPClient(
30+
server=settings.api.v2.server,
31+
base_url=settings.api.v2.base_url,
32+
api_key=settings.api.v2.api_key,
33+
timeout=settings.api.v2.timeout,
34+
retries=settings.connection.retries,
35+
delay_method=settings.connection.delay_method,
36+
delay_time=settings.connection.delay_time,
37+
)
38+
self.v1_api = TasksV1(v1_http_client)
39+
self.v2_api = TasksV2(v2_http_client)
2240

2341
def _get_first_tid(self, task_type: TaskType) -> int:
2442
"""Helper to find an existing task ID for a given type on the server."""
@@ -60,11 +78,8 @@ def test_v1_list_tasks(self):
6078
def test_v2_get_task(self):
6179
"""Verify TasksV2 (JSON) skips gracefully if V2 is not supported."""
6280
tid = self._get_first_tid(TaskType.SUPERVISED_CLASSIFICATION)
63-
try:
64-
task_v2 = self.v2_api.get(tid)
65-
assert int(task_v2.task_id) == tid
66-
except (requests.exceptions.JSONDecodeError, Exception):
67-
pytest.skip("V2 API JSON format not supported on this server.")
81+
task_v2 = self.v2_api.get(tid)
82+
assert int(task_v2.task_id) == tid
6883

6984
@pytest.mark.uses_test_server()
7085
def test_v1_estimation_procedure_list(self):

0 commit comments

Comments
 (0)