diff --git a/tests/test_tasks/test_split.py b/tests/test_tasks/test_split.py index 8e7f09439..373b479cd 100644 --- a/tests/test_tasks/test_split.py +++ b/tests/test_tasks/test_split.py @@ -9,6 +9,7 @@ from pathlib import Path import numpy as np +import pytest from openml import OpenMLSplit from openml.testing import TestBase @@ -87,17 +88,8 @@ 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( # noqa: PT027 - ValueError, - "Repeat 10 not known", - split.get, - 10, - 2, - ) - self.assertRaisesRegex( # noqa: PT027 - 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 9a23a7696..135f07ae9 100644 --- a/tests/test_tasks/test_supervised_task.py +++ b/tests/test_tasks/test_supervised_task.py @@ -1,8 +1,6 @@ # License: BSD 3-Clause from __future__ import annotations -import unittest - import pandas as pd import pytest @@ -22,7 +20,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): # noqa: ARG002 diff --git a/tests/test_tasks/test_task.py b/tests/test_tasks/test_task.py index 0f77dd505..be662a776 100644 --- a/tests/test_tasks/test_task.py +++ b/tests/test_tasks/test_task.py @@ -1,7 +1,6 @@ # License: BSD 3-Clause from __future__ import annotations -import unittest from random import randint, shuffle import pytest @@ -26,7 +25,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): # noqa: ARG002 diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index a535fc831..ee337308f 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 unittest import mock import pytest @@ -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( # noqa: PT027 - 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) @pytest.mark.test_server def test__get_estimation_procedure_list(self): @@ -141,8 +136,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_server 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 ceb1516c0..53e0a5e95 100644 --- a/tests/test_tasks/test_task_methods.py +++ b/tests/test_tasks/test_task_methods.py @@ -47,17 +47,8 @@ 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( # noqa: PT027 - ValueError, - "Fold 10 not known", - task.get_train_test_split_indices, - 10, - 0, - ) - self.assertRaisesRegex( # noqa: PT027 - 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)