From 2314cbca4656976222e7cebcab6db7114a33cd62 Mon Sep 17 00:00:00 2001 From: Sumit Saraswat Date: Sat, 3 Oct 2026 18:58:39 +0530 Subject: [PATCH] test: mock live server call in test_list_clustering_task Replaces the @pytest.mark.production_server() call in test_list_clustering_task with a mocked requests.Session.request using a saved XML response. Partial fix for #1649. --- tests/mock_data/clustering_tasks.xml | 209 ++++++++++++++++++++++++ tests/test_tasks/test_task_functions.py | 13 +- 2 files changed, 218 insertions(+), 4 deletions(-) create mode 100644 tests/mock_data/clustering_tasks.xml diff --git a/tests/mock_data/clustering_tasks.xml b/tests/mock_data/clustering_tasks.xml new file mode 100644 index 000000000..d71291ad3 --- /dev/null +++ b/tests/mock_data/clustering_tasks.xml @@ -0,0 +1,209 @@ + + + 126033 + 5 + Clustering + 2 + anneal + active + ARFF + 17 + 2 + 684.0 + 7.0 + 8.0 + 5.0 + 39.0 + 898.0 + 898.0 + 22175.0 + 6.0 + 33.0 + + + 126034 + 5 + Clustering + 3 + kr-vs-kp + active + ARFF + 17 + 3 + 1669.0 + 3.0 + 1527.0 + 2.0 + 37.0 + 3196.0 + 0.0 + 0.0 + 0.0 + 37.0 + + + 126035 + 5 + Clustering + 4 + labor + active + ARFF + 17 + 4 + 37.0 + 3.0 + 20.0 + 2.0 + 17.0 + 57.0 + 56.0 + 326.0 + 8.0 + 9.0 + + + 126036 + 5 + Clustering + 5 + arrhythmia + active + ARFF + 17 + 5 + 245.0 + 13.0 + 2.0 + 13.0 + 280.0 + 452.0 + 384.0 + 408.0 + 206.0 + 74.0 + + + 126037 + 5 + Clustering + 6 + letter + active + ARFF + 17 + 6 + 813.0 + 26.0 + 734.0 + 26.0 + 17.0 + 20000.0 + 0.0 + 0.0 + 16.0 + 1.0 + + + 126038 + 5 + Clustering + 7 + audiology + active + ARFF + 17 + 7 + 57.0 + 24.0 + 1.0 + 24.0 + 70.0 + 226.0 + 222.0 + 317.0 + 0.0 + 70.0 + + + 126039 + 5 + Clustering + 8 + liver-disorders + active + ARFF + 17 + 8 + 0.0 + 6.0 + 345.0 + 0.0 + 0.0 + 6.0 + 0.0 + + + 126040 + 5 + Clustering + 9 + autos + active + ARFF + 17 + 9 + 67.0 + 22.0 + 3.0 + 6.0 + 26.0 + 205.0 + 46.0 + 59.0 + 15.0 + 11.0 + + + 126041 + 5 + Clustering + 10 + lymph + active + ARFF + 17 + 10 + 81.0 + 8.0 + 2.0 + 4.0 + 19.0 + 148.0 + 0.0 + 0.0 + 3.0 + 16.0 + + + 126042 + 5 + Clustering + 11 + balance-scale + active + ARFF + 17 + 11 + 288.0 + 3.0 + 49.0 + 3.0 + 5.0 + 625.0 + 0.0 + 0.0 + 4.0 + 1.0 + + diff --git a/tests/test_tasks/test_task_functions.py b/tests/test_tasks/test_task_functions.py index bf2fcfeae..9b11513d7 100644 --- a/tests/test_tasks/test_task_functions.py +++ b/tests/test_tasks/test_task_functions.py @@ -56,10 +56,15 @@ def test__get_estimation_procedure_list(self): assert isinstance(estimation_procedures[0], dict) assert estimation_procedures[0]["task_type_id"] == TaskType.SUPERVISED_CLASSIFICATION - @pytest.mark.production_server() - @pytest.mark.xfail(reason="failures_issue_1544", strict=False) - def test_list_clustering_task(self): - self.use_production_server() + @mock.patch("requests.Session.request") + def test_list_clustering_task(self, mock_request): + import pathlib + mock_request.return_value = create_request_response( + status_code=200, + content_filepath=pathlib.Path(__file__).parent.parent + / "mock_data" + / "clustering_tasks.xml", + ) # as shown by #383, clustering tasks can give list/dict casting problems openml.tasks.list_tasks(task_type=TaskType.CLUSTERING, size=10) # the expected outcome is that it doesn't crash. No assertions.