Skip to content

Commit 94116e7

Browse files
authored
Automatically connect to production server based on mark (#1411)
1 parent d88f885 commit 94116e7

6 files changed

Lines changed: 37 additions & 22 deletions

File tree

.github/workflows/test.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,22 @@ jobs:
9696
echo "Repository status before tests: $git_status"
9797
- name: Show installed dependencies
9898
run: python -m pip list
99-
- name: Run tests on Ubuntu
99+
- name: Run tests on Ubuntu Test
100100
if: matrix.os == 'ubuntu-latest'
101101
run: |
102102
if [ ${{ matrix.code-cov }} ]; then codecov='--cov=openml --long --cov-report=xml'; fi
103103
# Most of the time, running only the scikit-learn tests is sufficient
104-
if [ ${{ matrix.sklearn-only }} = 'true' ]; then sklearn='-m sklearn'; fi
105-
echo pytest -n 4 --durations=20 --dist load -sv $codecov $sklearn -o log_cli=true
106-
pytest -n 4 --durations=20 --dist load -sv $codecov $sklearn -o log_cli=true
104+
if [ ${{ matrix.sklearn-only }} = 'true' ]; then marks='sklearn and not production'; else marks='not production'; fi
105+
echo pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
106+
pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
107+
- name: Run tests on Ubuntu Production
108+
if: matrix.os == 'ubuntu-latest'
109+
run: |
110+
if [ ${{ matrix.code-cov }} ]; then codecov='--cov=openml --long --cov-report=xml'; fi
111+
# Most of the time, running only the scikit-learn tests is sufficient
112+
if [ ${{ matrix.sklearn-only }} = 'true' ]; then marks='sklearn and production'; else marks='production'; fi
113+
echo pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
114+
pytest -n 4 --durations=20 --dist load -sv $codecov -o log_cli=true -m "$marks"
107115
- name: Run tests on Windows
108116
if: matrix.os == 'windows-latest'
109117
run: | # we need a separate step because of the bash-specific if-statement in the previous one.

openml/testing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def setUp(self, n_levels: int = 1, tmpdir_suffix: str = "") -> None:
101101
self.cached = True
102102
openml.config.apikey = TestBase.apikey
103103
self.production_server = "https://www.openml.org/api/v1/xml"
104-
openml.config.server = TestBase.test_server
105104
openml.config.avoid_duplicate_runs = False
106105
openml.config.set_root_cache_directory(str(self.workdir))
107106

@@ -120,7 +119,6 @@ def tearDown(self) -> None:
120119
# one of the files may still be used by another process
121120
raise e
122121

123-
openml.config.server = self.production_server
124122
openml.config.connection_n_retries = self.connection_n_retries
125123
openml.config.retry_policy = self.retry_policy
126124

tests/conftest.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,15 @@ def as_robot() -> Iterator[None]:
268268
openml.config.set_retry_policy(policy, n_retries)
269269

270270

271-
@pytest.fixture(autouse=True, scope="session")
272-
def with_test_server():
273-
openml.config.start_using_configuration_for_example()
271+
@pytest.fixture(autouse=True)
272+
def with_server(request):
273+
if "production" in request.keywords:
274+
openml.config.server = "https://www.openml.org/api/v1/xml"
275+
yield
276+
return
277+
openml.config.server = "https://test.openml.org/api/v1/xml"
278+
openml.config.apikey = "c0c42819af31e706efe1f4b88c23c6c1"
274279
yield
275-
openml.config.stop_using_configuration_for_example()
276280

277281

278282
@pytest.fixture(autouse=True)

tests/test_datasets/test_dataset_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,8 @@ def test_get_dataset_parquet(requests_mock, test_files_directory):
19511951
content_file = (
19521952
test_files_directory / "mock_responses" / "datasets" / "data_description_61.xml"
19531953
)
1954-
requests_mock.get("https://www.openml.org/api/v1/xml/data/61", text=content_file.read_text())
1954+
# While the mocked example is from production, unit tests by default connect to the test server.
1955+
requests_mock.get("https://test.openml.org/api/v1/xml/data/61", text=content_file.read_text())
19551956
dataset = openml.datasets.get_dataset(61, download_data=True)
19561957
assert dataset._parquet_url is not None
19571958
assert dataset.parquet_file is not None

tests/test_runs/test_run_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TestRun(TestBase):
6868
"task_meta_data": {
6969
"task_type": TaskType.SUPERVISED_CLASSIFICATION,
7070
"dataset_id": 16, # credit-a
71-
"estimation_procedure_id": 1,
71+
"estimation_procedure_id": 6,
7272
"target_name": "class",
7373
},
7474
}
@@ -81,7 +81,7 @@ class TestRun(TestBase):
8181
"task_meta_data": {
8282
"task_type": TaskType.SUPERVISED_CLASSIFICATION,
8383
"dataset_id": 20, # diabetes
84-
"estimation_procedure_id": 1,
84+
"estimation_procedure_id": 5,
8585
"target_name": "class",
8686
},
8787
}

tests/test_tasks/test_classification_task.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
import pandas as pd
5+
import pytest
56

67
from openml.tasks import TaskType, get_task
78

@@ -17,14 +18,6 @@ def setUp(self, n_levels: int = 1):
1718
self.task_type = TaskType.SUPERVISED_CLASSIFICATION
1819
self.estimation_procedure = 5
1920

20-
def test_get_X_and_Y(self):
21-
X, Y = super().test_get_X_and_Y()
22-
assert X.shape == (768, 8)
23-
assert isinstance(X, pd.DataFrame)
24-
assert Y.shape == (768,)
25-
assert isinstance(Y, pd.Series)
26-
assert pd.api.types.is_categorical_dtype(Y)
27-
2821
def test_download_task(self):
2922
task = super().test_download_task()
3023
assert task.task_id == self.task_id
@@ -34,4 +27,15 @@ def test_download_task(self):
3427

3528
def test_class_labels(self):
3629
task = get_task(self.task_id)
37-
assert task.class_labels == ["tested_negative", "tested_positive"]
30+
assert task.class_labels == ["tested_negative", "tested_positive"]
31+
32+
33+
@pytest.mark.server()
34+
def test_get_X_and_Y():
35+
task = get_task(119)
36+
X, Y = task.get_X_and_y()
37+
assert X.shape == (768, 8)
38+
assert isinstance(X, pd.DataFrame)
39+
assert Y.shape == (768,)
40+
assert isinstance(Y, pd.Series)
41+
assert pd.api.types.is_categorical_dtype(Y)

0 commit comments

Comments
 (0)