[MNT] Replace live server calls with mocks in test_setup_functions.py#1674
[MNT] Replace live server calls with mocks in test_setup_functions.py#1674Sandipmandal25 wants to merge 1 commit intoopenml:mainfrom
Conversation
There was a problem hiding this comment.
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.getmocking 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.
test_setup_functions.py
b09a611 to
4062ce4
Compare
| "</oml:error>" | ||
| ).encode() | ||
| return response | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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() |
Metadata
test_setup_functions.py)test_setup_functions.py"Removes
@pytest.mark.test_server()from three tests inTestSetupFunctionssince 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