Skip to content

Comments

[MNT] Replace live server calls with mocks in test_list_flows (test_flows/test_flow_functions.py)#1670

Open
anuj452005 wants to merge 1 commit intoopenml:mainfrom
anuj452005:mock-test-list-flows
Open

[MNT] Replace live server calls with mocks in test_list_flows (test_flows/test_flow_functions.py)#1670
anuj452005 wants to merge 1 commit intoopenml:mainfrom
anuj452005:mock-test-list-flows

Conversation

@anuj452005
Copy link

Metadata

Details

This PR converts test_list_flows in tests/test_flows/test_flow_functions.py from a
@pytest.mark.production_server test (requiring a live connection to openml.org) into an
offline unit test using unittest.mock.

Changes

  • Removed TestFlowFunctions.test_list_flows (class method marked @pytest.mark.production_server)
  • Added module-level test_list_flows function using @mock.patch.object(requests.Session, "get"),
    consistent with the existing test_delete_flow_* pattern in the same file
  • Added tests/files/mock_responses/flows/flow_list.xml — a minimal fixture with 2 flows
    containing all 6 fields read by __list_flows (id, full_name, name, version,
    external_version, uploader)

    Testing

# Passes offline, no network required
pytest tests/test_flows/test_flow_functions.py::test_list_flows -v

@anuj452005
Copy link
Author

@geetu040 review please .

assert ext_version_str_or_none

@pytest.mark.production_server()
def test_list_flows(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you have to remove test_list_flows from being a class method?

assert isinstance(flow["full_name"], str)
assert isinstance(flow["version"], str)
ext_v = flow["external_version"]
assert isinstance(ext_v, str) or ext_v is None or pd.isna(ext_v)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not need, since we are using hard-coded flows, these checks should always pass

Comment on lines +559 to +562
# Verify the mock was called and URL contains the list endpoint
assert mock_get.called
call_url = mock_get.call_args.args[0]
assert "flow/list" in call_url
Copy link
Collaborator

Choose a reason for hiding this comment

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

are you checking all the parameters? make sure you verify each argument that was given to Session.get

Copy link
Author

Choose a reason for hiding this comment

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

okk , I will update it to check the exact full URL and verify all the kwargs (like api_key).

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.

2 participants