@@ -8,17 +8,18 @@ def test_a2a_warning_shown_once():
88 with warnings .catch_warnings (record = True ) as caught :
99 warnings .simplefilter ("always" )
1010
11- # Re-install the filter as types.py does at import time (scoped to google.adk)
11+ # Re-install the filter as types.py does at import time
12+ # (scoped to the specific remote_a2a_agent module)
1213 warnings .filterwarnings (
1314 "once" ,
1415 message = r"\[EXPERIMENTAL\].*A2A" ,
1516 category = UserWarning ,
16- module = r"^google\.adk\." ,
17+ module = r"^google\.adk\.agents\.remote_a2a_agent$ " ,
1718 )
1819
19- # Simulate a warning from a google.adk module by executing in a
20+ # Simulate a warning from the exact upstream module by executing in a
2021 # namespace whose __name__ matches the module filter.
21- adk_globals = {"__name__" : "google.adk.a2a.remote " , "__file__" : __file__ }
22+ adk_globals = {"__name__" : "google.adk.agents.remote_a2a_agent " , "__file__" : __file__ }
2223 code = compile (
2324 'import warnings; warnings.warn("[EXPERIMENTAL] A2A support is experimental", UserWarning, stacklevel=1)' ,
2425 "<test>" ,
@@ -29,11 +30,11 @@ def test_a2a_warning_shown_once():
2930 assert len (caught ) == 1 , "First A2A warning should be recorded"
3031
3132 exec (code , adk_globals ) # noqa: S102
32- assert len (caught ) == 1 , "Duplicate A2A warning from google.adk should be suppressed"
33+ assert len (caught ) == 1 , "Duplicate A2A warning from remote_a2a_agent should be suppressed"
3334
3435
3536def test_filter_does_not_suppress_non_adk_warnings ():
36- """The filter should not suppress warnings from modules outside google.adk ."""
37+ """The filter should not suppress warnings from modules outside remote_a2a_agent ."""
3738 with warnings .catch_warnings (record = True ) as caught :
3839 warnings .simplefilter ("always" )
3940
@@ -42,13 +43,42 @@ def test_filter_does_not_suppress_non_adk_warnings():
4243 "once" ,
4344 message = r"\[EXPERIMENTAL\].*A2A" ,
4445 category = UserWarning ,
45- module = r"^google\.adk\." ,
46+ module = r"^google\.adk\.agents\.remote_a2a_agent$ " ,
4647 )
4748
48- # A warning from the current test module (not google.adk.* ) should not be suppressed
49+ # A warning from the current test module (not remote_a2a_agent ) should not be suppressed
4950 warnings .warn ("[EXPERIMENTAL] A2A support is experimental" , UserWarning , stacklevel = 1 )
5051 assert len (caught ) == 1
5152
5253 warnings .warn ("[EXPERIMENTAL] A2A support is experimental" , UserWarning , stacklevel = 1 )
53- # Both should be recorded because this module is not google.adk.*
54- assert len (caught ) == 2 , "Warnings from non-google.adk modules should not be suppressed"
54+ # Both should be recorded because this module is not google.adk.agents.remote_a2a_agent
55+ assert len (caught ) == 2 , "Warnings from non-remote_a2a_agent modules should not be suppressed"
56+
57+
58+ def test_filter_does_not_suppress_other_adk_modules ():
59+ """The filter should not suppress warnings from other google.adk submodules."""
60+ with warnings .catch_warnings (record = True ) as caught :
61+ warnings .simplefilter ("always" )
62+
63+ # Install the scoped filter (exact module match only)
64+ warnings .filterwarnings (
65+ "once" ,
66+ message = r"\[EXPERIMENTAL\].*A2A" ,
67+ category = UserWarning ,
68+ module = r"^google\.adk\.agents\.remote_a2a_agent$" ,
69+ )
70+
71+ # A warning from a different google.adk submodule should NOT be suppressed
72+ other_adk_globals = {"__name__" : "google.adk.a2a.executor" , "__file__" : __file__ }
73+ code = compile (
74+ 'import warnings; warnings.warn("[EXPERIMENTAL] A2A support is experimental", UserWarning, stacklevel=1)' ,
75+ "<test>" ,
76+ "exec" ,
77+ )
78+
79+ exec (code , other_adk_globals ) # noqa: S102
80+ assert len (caught ) == 1
81+
82+ exec (code , other_adk_globals ) # noqa: S102
83+ # Both should be recorded because the module doesn't match remote_a2a_agent exactly
84+ assert len (caught ) == 2 , "Warnings from other google.adk modules should not be suppressed"
0 commit comments