Skip to content

Commit 2b2f0b5

Browse files
Jacksunweicopybara-github
authored andcommitted
chore: Fixes a2a tests for python 3.9
A more common approach is to just skip entire module in pytest. PiperOrigin-RevId: 799164877
1 parent 0eb65c0 commit 2b2f0b5

File tree

2 files changed

+30
-53
lines changed

2 files changed

+30
-53
lines changed

tests/unittests/a2a/executor/test_task_result_aggregator.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,19 @@
1717

1818
import pytest
1919

20-
# Skip all tests in this module if Python version is less than 3.10
21-
pytestmark = pytest.mark.skipif(
22-
sys.version_info < (3, 10), reason="A2A requires Python 3.10+"
23-
)
24-
25-
# Import dependencies with version checking
26-
try:
27-
from a2a.types import Message
28-
from a2a.types import Part
29-
from a2a.types import Role
30-
from a2a.types import TaskState
31-
from a2a.types import TaskStatus
32-
from a2a.types import TaskStatusUpdateEvent
33-
from a2a.types import TextPart
34-
from google.adk.a2a.executor.task_result_aggregator import TaskResultAggregator
35-
except ImportError as e:
36-
if sys.version_info < (3, 10):
37-
# Create dummy classes to prevent NameError during test collection
38-
# Tests will be skipped anyway due to pytestmark
39-
class DummyTypes:
40-
pass
41-
42-
TaskState = DummyTypes()
43-
TaskStatus = DummyTypes()
44-
TaskStatusUpdateEvent = DummyTypes()
45-
TaskResultAggregator = DummyTypes()
46-
else:
47-
raise e
20+
# Skip entire module if Python < 3.10
21+
if sys.version_info < (3, 10):
22+
pytest.skip("A2A requires Python 3.10+", allow_module_level=True)
23+
24+
# Normal imports after the skip
25+
from a2a.types import Message
26+
from a2a.types import Part
27+
from a2a.types import Role
28+
from a2a.types import TaskState
29+
from a2a.types import TaskStatus
30+
from a2a.types import TaskStatusUpdateEvent
31+
from a2a.types import TextPart
32+
from google.adk.a2a.executor.task_result_aggregator import TaskResultAggregator
4833

4934

5035
def create_test_message(text: str) -> Message:

tests/unittests/a2a/logs/test_log_utils.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,35 @@
1515
"""Tests for log_utils module."""
1616

1717
import json
18+
import sys
1819
from unittest.mock import Mock
1920
from unittest.mock import patch
2021

2122
import pytest
2223

23-
# Import the actual A2A types that we need to mock
24-
try:
25-
from a2a.types import DataPart as A2ADataPart
26-
from a2a.types import Message as A2AMessage
27-
from a2a.types import MessageSendConfiguration
28-
from a2a.types import MessageSendParams
29-
from a2a.types import Part as A2APart
30-
from a2a.types import Role
31-
from a2a.types import SendMessageRequest
32-
from a2a.types import Task as A2ATask
33-
from a2a.types import TaskState
34-
from a2a.types import TaskStatus
35-
from a2a.types import TextPart as A2ATextPart
36-
37-
A2A_AVAILABLE = True
38-
except ImportError:
39-
A2A_AVAILABLE = False
24+
# Skip entire module if Python < 3.10
25+
if sys.version_info < (3, 10):
26+
pytest.skip("A2A requires Python 3.10+", allow_module_level=True)
27+
28+
# Normal imports after the skip
29+
from a2a.types import DataPart as A2ADataPart
30+
from a2a.types import Message as A2AMessage
31+
from a2a.types import MessageSendConfiguration
32+
from a2a.types import MessageSendParams
33+
from a2a.types import Part as A2APart
34+
from a2a.types import Role
35+
from a2a.types import SendMessageRequest
36+
from a2a.types import Task as A2ATask
37+
from a2a.types import TaskState
38+
from a2a.types import TaskStatus
39+
from a2a.types import TextPart as A2ATextPart
4040

4141

4242
class TestBuildMessagePartLog:
4343
"""Test suite for build_message_part_log function."""
4444

45-
@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
4645
def test_text_part_short_text(self):
4746
"""Test TextPart with short text."""
48-
# Import here to avoid import issues at module level
4947
from google.adk.a2a.logs.log_utils import build_message_part_log
5048

5149
# Create real A2A objects
@@ -56,7 +54,6 @@ def test_text_part_short_text(self):
5654

5755
assert result == "TextPart: Hello, world!"
5856

59-
@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
6057
def test_text_part_long_text(self):
6158
"""Test TextPart with long text that gets truncated."""
6259
from google.adk.a2a.logs.log_utils import build_message_part_log
@@ -70,7 +67,6 @@ def test_text_part_long_text(self):
7067
expected = f"TextPart: {'x' * 100}..."
7168
assert result == expected
7269

73-
@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
7470
def test_data_part_simple_data(self):
7571
"""Test DataPart with simple data."""
7672
from google.adk.a2a.logs.log_utils import build_message_part_log
@@ -84,7 +80,6 @@ def test_data_part_simple_data(self):
8480
expected = f"DataPart: {json.dumps(expected_data, indent=2)}"
8581
assert result == expected
8682

87-
@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
8883
def test_data_part_large_values(self):
8984
"""Test DataPart with large values that get summarized."""
9085
from google.adk.a2a.logs.log_utils import build_message_part_log
@@ -278,7 +273,6 @@ def test_error_response_no_data(self):
278273
assert "Not Found" in result
279274
assert "Error Data: None" in result
280275

281-
@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
282276
def test_success_response_with_task(self):
283277
"""Test success response logging with Task result."""
284278
# Use module-level imported types consistently
@@ -309,7 +303,6 @@ def test_success_response_with_task(self):
309303
or '"state": "working"' in result
310304
)
311305

312-
@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
313306
def test_success_response_with_task_and_status_message(self):
314307
"""Test success response with Task that has status message."""
315308
from google.adk.a2a.logs.log_utils import build_a2a_response_log
@@ -353,7 +346,6 @@ def test_success_response_with_task_and_status_message(self):
353346
)
354347
assert "Message Parts:" in result
355348

356-
@pytest.mark.skipif(not A2A_AVAILABLE, reason="A2A types not available")
357349
def test_success_response_with_message(self):
358350
"""Test success response logging with Message result."""
359351
from google.adk.a2a.logs.log_utils import build_a2a_response_log

0 commit comments

Comments
 (0)