From e321cd2511d5de14432143eb1e505531914efcca Mon Sep 17 00:00:00 2001 From: naman9271 Date: Sun, 16 Nov 2025 13:03:44 +0530 Subject: [PATCH] migrated test_tasks successfully --- tests/test_tasks/test_split.py | 21 +++++++-------------- tests/test_tasks/test_supervised_task.py | 4 ++-- tests/test_tasks/test_task.py | 4 ++-- tests/test_tasks/test_task_functions.py | 13 ++++--------- tests/test_tasks/test_task_methods.py | 22 ++++++++-------------- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/tests/test_tasks/test_split.py b/tests/test_tasks/test_split.py index 12cb632d9..a2d88052c 100644 --- a/tests/test_tasks/test_split.py +++ b/tests/test_tasks/test_split.py @@ -6,6 +6,7 @@ from pathlib import Path import numpy as np +import pytest from openml import OpenMLSplit from openml.testing import TestBase @@ -82,17 +83,9 @@ def test_get_split(self): train_split, test_split = split.get(fold=5, repeat=2) assert train_split.shape[0] == 808 assert test_split.shape[0] == 90 - self.assertRaisesRegex( - ValueError, - "Repeat 10 not known", - split.get, - 10, - 2, - ) - self.assertRaisesRegex( - ValueError, - "Fold 10 not known", - split.get, - 2, - 10, - ) + + with pytest.raises(ValueError, match="Repeat 10 not known"): + split.get(10, 2) + + with pytest.raises(ValueError, match="Fold 10 not known"): + split.get(2, 10) diff --git a/tests/test_tasks/test_supervised_task.py b/tests/test_tasks/test_supervised_task.py index 9c90b7e03..e4ee3805c 100644 --- a/tests/test_tasks/test_supervised_task.py +++ b/tests/test_tasks/test_supervised_task.py @@ -1,7 +1,7 @@ # License: BSD 3-Clause from __future__ import annotations -import unittest +import pytest import pandas as pd @@ -21,7 +21,7 @@ class OpenMLSupervisedTaskTest(OpenMLTaskTest): @classmethod def setUpClass(cls): if cls is OpenMLSupervisedTaskTest: - raise unittest.SkipTest("Skip OpenMLSupervisedTaskTest tests," " it's a base class") + pytest.skip("Skip OpenMLSupervisedTaskTest tests, it's a base class") super().setUpClass() def setUp(self, n_levels: int = 1): diff --git a/tests/test_tasks/test_task.py b/tests/test_tasks/test_task.py index e4c9418f2..5d1f90a3c 100644 --- a/tests/test_tasks/test_task.py +++ b/tests/test_tasks/test_task.py @@ -1,7 +1,7 @@ # License: BSD 3-Clause from __future__ import annotations -import unittest +import pytest from random import randint, shuffle from openml.datasets import ( @@ -24,7 +24,7 @@ class OpenMLTaskTest(TestBase): @classmethod def setUpClass(cls): if cls is OpenMLTaskTest: - raise unittest.SkipTest("Skip OpenMLTaskTest tests," " it's a base class") + pytest.skip("Skip OpenMLTaskTest tests, it's a base class") super().setUpClass() def setUp(self, n_levels: int = 1): diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index 856352ac2..dbc625878 100644 --- a/tests/test_tasks/test_task_functions.py +++ b/tests/test_tasks/test_task_functions.py @@ -2,7 +2,6 @@ from __future__ import annotations import os -import unittest from typing import cast from unittest import mock @@ -40,12 +39,8 @@ def test__get_cached_task(self): def test__get_cached_task_not_cached(self): openml.config.set_root_cache_directory(self.static_cache_dir) - self.assertRaisesRegex( - OpenMLCacheException, - "Task file for tid 2 not cached", - openml.tasks.functions._get_cached_task, - 2, - ) + with pytest.raises(OpenMLCacheException, match="Task file for tid 2 not cached"): + openml.tasks.functions._get_cached_task(2) def test__get_estimation_procedure_list(self): estimation_procedures = openml.tasks.functions._get_estimation_procedure_list() @@ -129,8 +124,8 @@ def test__get_task(self): openml.config.set_root_cache_directory(self.static_cache_dir) openml.tasks.get_task(1882) - @unittest.skip( - "Please await outcome of discussion: https://github.com/openml/OpenML/issues/776", + @pytest.mark.skip( + reason="Please await outcome of discussion: https://github.com/openml/OpenML/issues/776", ) @pytest.mark.production() def test__get_task_live(self): diff --git a/tests/test_tasks/test_task_methods.py b/tests/test_tasks/test_task_methods.py index 4480c2cbc..70bc5566e 100644 --- a/tests/test_tasks/test_task_methods.py +++ b/tests/test_tasks/test_task_methods.py @@ -3,6 +3,8 @@ from time import time +import pytest + import openml from openml.testing import TestBase @@ -43,17 +45,9 @@ def test_get_train_and_test_split_indices(self): assert train_indices[-1] == 681 assert test_indices[0] == 583 assert test_indices[-1] == 24 - self.assertRaisesRegex( - ValueError, - "Fold 10 not known", - task.get_train_test_split_indices, - 10, - 0, - ) - self.assertRaisesRegex( - ValueError, - "Repeat 10 not known", - task.get_train_test_split_indices, - 0, - 10, - ) + + with pytest.raises(ValueError, match="Fold 10 not known"): + task.get_train_test_split_indices(10, 0) + + with pytest.raises(ValueError, match="Repeat 10 not known"): + task.get_train_test_split_indices(0, 10)