Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ known_third_party = ["google.adk"]

[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = "src"
asyncio_default_fixture_loop_scope = "function"
asyncio_mode = "auto"

Expand Down
9 changes: 5 additions & 4 deletions tests/unittests/agents/test_remote_a2a_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tempfile
from unittest.mock import AsyncMock
from unittest.mock import create_autospec
from unittest.mock import MagicMock
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While MagicMock is functional, create_autospec provides stronger type checking and ensures that the mock adheres more closely to the A2AClient interface. This can help catch potential API mismatches or typos during testing, leading to more robust tests. Consider using create_autospec for better test safety.

Suggested change
from unittest.mock import MagicMock
from unittest.mock import create_autospec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test failed if I use create_autospec

from unittest.mock import Mock
from unittest.mock import patch

Expand Down Expand Up @@ -1002,7 +1003,7 @@ async def test_handle_a2a_response_with_task_submitted_and_no_update(self):
mock_a2a_task,
self.agent.name,
self.mock_context,
self.mock_a2a_part_converter,
self.agent._a2a_part_converter,
)
# Check the parts are updated as Thought
assert result.content.parts[0].thought is True
Expand Down Expand Up @@ -1770,7 +1771,7 @@ async def test_run_async_impl_successful_request(self):
) # Tuple with parts and context_id

# Mock A2A client
mock_a2a_client = create_autospec(spec=A2AClient, instance=True)
mock_a2a_client = MagicMock(spec=A2AClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Changing from create_autospec(spec=A2AClient, instance=True) to MagicMock(spec=A2AClient) reduces the strictness of the mock. create_autospec is generally preferred for unit tests as it ensures the mock's interface matches the real object, which can prevent subtle bugs. I recommend reverting to create_autospec for improved test robustness.

Suggested change
mock_a2a_client = MagicMock(spec=A2AClient)
mock_a2a_client = create_autospec(spec=A2AClient, instance=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test failed if I use create_autospec

mock_response = Mock()
mock_send_message = AsyncMock()
mock_send_message.__aiter__.return_value = [mock_response]
Expand Down Expand Up @@ -1909,7 +1910,7 @@ async def test_run_async_impl_with_meta_provider(self):
) # Tuple with parts and context_id

# Mock A2A client
mock_a2a_client = create_autospec(spec=A2AClient, instance=True)
mock_a2a_client = MagicMock(spec=A2AClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Changing from create_autospec(spec=A2AClient, instance=True) to MagicMock(spec=A2AClient) reduces the strictness of the mock. create_autospec is generally preferred for unit tests as it ensures the mock's interface matches the real object, which can prevent subtle bugs. I recommend reverting to create_autospec for improved test robustness.

Suggested change
mock_a2a_client = MagicMock(spec=A2AClient)
mock_a2a_client = create_autospec(spec=A2AClient, instance=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test failed if I use create_autospec

mock_response = Mock()
mock_send_message = AsyncMock()
mock_send_message.__aiter__.return_value = [mock_response]
Expand Down Expand Up @@ -2046,7 +2047,7 @@ async def test_run_async_impl_successful_request(self):
) # Tuple with parts and context_id

# Mock A2A client
mock_a2a_client = create_autospec(spec=A2AClient, instance=True)
mock_a2a_client = MagicMock(spec=A2AClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Changing from create_autospec(spec=A2AClient, instance=True) to MagicMock(spec=A2AClient) reduces the strictness of the mock. create_autospec is generally preferred for unit tests as it ensures the mock's interface matches the real object, which can prevent subtle bugs. I recommend reverting to create_autospec for improved test robustness.

Suggested change
mock_a2a_client = MagicMock(spec=A2AClient)
mock_a2a_client = create_autospec(spec=A2AClient, instance=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test failed if I use create_autospec

mock_response = Mock()
mock_send_message = AsyncMock()
mock_send_message.__aiter__.return_value = [mock_response]
Expand Down
Loading