Skip to content

Comments

MNT: Replace live server calls with mocks in tests/test_utils/test_utils.py#1679

Open
Rahuldrabit wants to merge 1 commit intoopenml:mainfrom
Rahuldrabit:rahul/mocks-test-utils
Open

MNT: Replace live server calls with mocks in tests/test_utils/test_utils.py#1679
Rahuldrabit wants to merge 1 commit intoopenml:mainfrom
Rahuldrabit:rahul/mocks-test-utils

Conversation

@Rahuldrabit
Copy link

Replace tests' live-server network calls with local mocks/patches so tests run deterministically and offline.
Add helpers to mock listing endpoints and API call responses (for datasets, tasks, flows, setups, runs, evaluations).
Patch cache/config calls and use tmp_path where needed to test cache utilities without touching real filesystem config.
No production code changes; test-only changes.
Addresses part of issue #1649.

Copilot AI review requested due to automatic review settings February 21, 2026 03:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces live server network calls with local mocks in tests/test_utils/test_utils.py to make tests run deterministically and offline, addressing part of issue #1649. The changes are test-only with no production code modifications.

Changes:

  • Added helper function _create_mock_listing_call to generate mock responses for paginated listing endpoints
  • Modified _mocked_perform_api_call to return mock XML responses for dataset queries
  • Updated 10 test functions to use mocks instead of live server calls, removing @pytest.mark.test_server() and @pytest.mark.flaky() markers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mock_list_setups.side_effect = _create_mock_listing_call(
min_number_setups_on_test_server,
lambda i: OpenMLSetup(setup_id=i, flow_id=1, parameters={}),
return_type="list"
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation for multi-line function call. The closing parenthesis should be on a new line at the same indentation level as the opening line of the function call, consistent with how similar calls are formatted elsewhere in the file (e.g., lines 82-84, 91-93, 107-109, 121-123).

Suggested change
return_type="list"
return_type="list",

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +156
run_id=i, task_id=1, setup_id=1, flow_id=1, flow_name="flow", data_id=1, data_name="data",
function="predictive_accuracy", upload_time="2020-01-01", uploader=1, uploader_name="user",
value=0.5, values=None
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation for multi-line function call. The closing parenthesis should be on a new line at the same indentation level as the opening line of the function call, consistent with how similar calls are formatted elsewhere in the file (e.g., lines 82-84, 91-93, 107-109, 121-123).

Suggested change
run_id=i, task_id=1, setup_id=1, flow_id=1, flow_name="flow", data_id=1, data_name="data",
function="predictive_accuracy", upload_time="2020-01-01", uploader=1, uploader_name="user",
value=0.5, values=None
run_id=i,
task_id=1,
setup_id=1,
flow_id=1,
flow_name="flow",
data_id=1,
data_name="data",
function="predictive_accuracy",
upload_time="2020-01-01",
uploader=1,
uploader_name="user",
value=0.5,
values=None,

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +156
run_id=i, task_id=1, setup_id=1, flow_id=1, flow_name="flow", data_id=1, data_name="data",
function="predictive_accuracy", upload_time="2020-01-01", uploader=1, uploader_name="user",
value=0.5, values=None
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line exceeds recommended maximum line length. The OpenMLEvaluation constructor call has very long lines (line 154 appears to be particularly long). Consider breaking this into multiple lines with one parameter per line for better readability.

Suggested change
run_id=i, task_id=1, setup_id=1, flow_id=1, flow_name="flow", data_id=1, data_name="data",
function="predictive_accuracy", upload_time="2020-01-01", uploader=1, uploader_name="user",
value=0.5, values=None
run_id=i,
task_id=1,
setup_id=1,
flow_id=1,
flow_name="flow",
data_id=1,
data_name="data",
function="predictive_accuracy",
upload_time="2020-01-01",
uploader=1,
uploader_name="user",
value=0.5,
values=None,

Copilot uses AI. Check for mistakes.
def _mocked_perform_api_call(call, request_method):
url = openml.config.server + "/" + call
return openml._api_calls._download_text_file(url)

Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line before function definition. According to PEP 8, there should be two blank lines before top-level function definitions. There's an extra blank line at line 51 which makes it appear there are two blank lines, but the standard convention is to have exactly two blank lines, not one followed by an extra one.

Suggested change

Copilot uses AI. Check for mistakes.
items = [item_factory(i) for i in range(offset, offset + size)]
return pd.DataFrame(items) if return_type == "dataframe" else items
return mock_listing_call

Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line between function definitions. According to PEP 8, there should be two blank lines between top-level function definitions.

Suggested change

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant