Skip to content

Comments

[MNT] Replace live server calls with mocks in test_setup_functions.py#1674

Open
Sandipmandal25 wants to merge 1 commit intoopenml:mainfrom
Sandipmandal25:mnt/mock-test-setup-functions
Open

[MNT] Replace live server calls with mocks in test_setup_functions.py#1674
Sandipmandal25 wants to merge 1 commit intoopenml:mainfrom
Sandipmandal25:mnt/mock-test-setup-functions

Conversation

@Sandipmandal25
Copy link

Metadata

Removes @pytest.mark.test_server() from three tests in TestSetupFunctions since they rely on mocking and do not require a live server.

  • test_list_setups_empty: Mocks HTTP 412 (error 674) and verifies empty dict handling.
  • test_setuplist_offset: Mocks paginated responses (offset/0 - 1–10, offset/10 - 11–20) and preserves non-overlap assertion.
  • test_get_cached_setup: Uses existing static cache; no server dependency.

The four tests marked with both @pytest.mark.sklearn() and @pytest.mark.test_server() are unchanged.

Test Run

tests/test_setups/test_setup_functions.py::TestSetupFunctions::test_get_cached_setup PASSED
tests/test_setups/test_setup_functions.py::TestSetupFunctions::test_get_uncached_setup PASSED
tests/test_setups/test_setup_functions.py::TestSetupFunctions::test_list_setups_empty PASSED
tests/test_setups/test_setup_functions.py::TestSetupFunctions::test_setuplist_offset PASSED

4 passed in 0.09s

Copilot AI review requested due to automatic review settings February 20, 2026 07:30
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 updates TestSetupFunctions unit tests to avoid requiring a live OpenML test server by replacing live HTTP calls with mocked requests responses, improving test reliability and reducing external dependencies.

Changes:

  • Removed @pytest.mark.test_server() from three setup-listing/cache tests that can run fully offline.
  • Added requests.Session.get mocking to simulate (a) “no results” server responses and (b) paginated listing behavior.
  • Kept the existing server-dependent sklearn tests unchanged.

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

"</oml:error>"
).encode()
return response

Choose a reason for hiding this comment

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

You can use from openml.testing import create_request_response function to get this mock response instead of implementing it again.
You can save this .xml content to tests/files/mock_responses and load it from there instead of writing the content here.

Copy link
Author

Choose a reason for hiding this comment

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

could use it but needs a new XML file in tests/files/mock_responses/
test_setuplist_offset generates setup IDs dynamically in a loop so create_request_response (which reads from a file) doesn't apply here. For test_list_setups_empty the content is static happy to add an XML file if preferred but wanted to keep the PR minimal. Let me know!

Choose a reason for hiding this comment

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

Ohh, i didn't know the first one is dynamic. However, I think you can create XML for 2nd one.

response.headers["Content-Encoding"] = "gzip"
response._content = (
f'<oml:setups xmlns:oml="http://openml.org/openml">{items}</oml:setups>'
).encode()

Choose a reason for hiding this comment

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

Same as above,

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.

[MNT] Replace Live Server Calls with Mocks in Unit Tests

2 participants