Skip to content

Commit eb53675

Browse files
DeanChensjcopybara-github
authored andcommitted
test(litellm): scope caplog to google_adk in tool call parsing tests
Fix flaky logger level assertions in LiteLLM tool call arguments tests by scoping caplog.at_level to the google_adk logger. In full test suite runs, preceding tests set the google_adk logger level to INFO, preventing root logger level changes in caplog from activating DEBUG-level logging in child loggers. Co-authored-by: Shangjie Chen <[email protected]> PiperOrigin-RevId: 996807646
1 parent ff75783 commit eb53675

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎tests/unittests/models/test_litellm.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10989,15 +10989,15 @@ def test_ambiguous_and_malformed_arguments_raise(self, arguments):
1098910989

1099010990
def test_repaired_arguments_log_warning_without_raw_payload(self, caplog):
1099110991
"""Repaired non-strict JSON arguments emit a warning without raw payload."""
10992-
with caplog.at_level(logging.WARNING):
10992+
with caplog.at_level(logging.WARNING, logger="google_adk"):
1099310993
_parse_tool_call_arguments("{a: 1}", function_name="test_fn")
1099410994
assert "Repaired" in caplog.text
1099510995
assert "test_fn" in caplog.text
1099610996
assert "{a: 1}" not in caplog.text
1099710997

1099810998
def test_repaired_arguments_log_debug_with_raw_payload(self, caplog):
1099910999
"""Repaired non-strict JSON arguments emit warning with payload at debug level."""
11000-
with caplog.at_level(logging.DEBUG):
11000+
with caplog.at_level(logging.DEBUG, logger="google_adk"):
1100111001
_parse_tool_call_arguments("{a: 1}", function_name="test_fn")
1100211002
assert "test_fn" in caplog.text
1100311003
assert "{a: 1}" in caplog.text
@@ -11009,13 +11009,13 @@ def test_repaired_arguments_log_debug_with_raw_payload(self, caplog):
1100911009

1101011010
def test_repaired_arguments_without_function_name(self, caplog):
1101111011
"""Repaired arguments log correctly without function_name."""
11012-
with caplog.at_level(logging.WARNING):
11012+
with caplog.at_level(logging.WARNING, logger="google_adk"):
1101311013
_parse_tool_call_arguments("{a: 1}")
1101411014
assert "Repaired" in caplog.text
1101511015
assert "{a: 1}" not in caplog.text
1101611016

1101711017
caplog.clear()
11018-
with caplog.at_level(logging.DEBUG):
11018+
with caplog.at_level(logging.DEBUG, logger="google_adk"):
1101911019
_parse_tool_call_arguments("{a: 1}")
1102011020
warning_records = [
1102111021
r for r in caplog.records if r.levelno == logging.WARNING
@@ -11025,11 +11025,11 @@ def test_repaired_arguments_without_function_name(self, caplog):
1102511025

1102611026
def test_literal_eval_layer_logs_debug_not_warning(self, caplog):
1102711027
"""Python dict literal arguments log at debug rather than warning."""
11028-
with caplog.at_level(logging.WARNING):
11028+
with caplog.at_level(logging.WARNING, logger="google_adk"):
1102911029
_parse_tool_call_arguments("{'a': 1}", function_name="test_fn")
1103011030
assert not any(r.levelno == logging.WARNING for r in caplog.records)
1103111031

11032-
with caplog.at_level(logging.DEBUG):
11032+
with caplog.at_level(logging.DEBUG, logger="google_adk"):
1103311033
_parse_tool_call_arguments("{'a': 1}", function_name="test_fn")
1103411034
assert not any(r.levelno == logging.WARNING for r in caplog.records)
1103511035
debug_records = [
@@ -11043,7 +11043,7 @@ def test_literal_eval_layer_logs_debug_not_warning(self, caplog):
1104311043

1104411044
def test_literal_eval_without_function_name_logs_debug(self, caplog):
1104511045
"""Python dict literal without function_name logs at debug."""
11046-
with caplog.at_level(logging.DEBUG):
11046+
with caplog.at_level(logging.DEBUG, logger="google_adk"):
1104711047
_parse_tool_call_arguments("{'a': 1}")
1104811048
assert not any(r.levelno == logging.WARNING for r in caplog.records)
1104911049
debug_records = [
@@ -11056,6 +11056,6 @@ def test_literal_eval_without_function_name_logs_debug(self, caplog):
1105611056

1105711057
def test_strict_json_does_not_log_warning(self, caplog):
1105811058
"""Strict JSON arguments parse without warning logs."""
11059-
with caplog.at_level(logging.WARNING):
11059+
with caplog.at_level(logging.WARNING, logger="google_adk"):
1106011060
_parse_tool_call_arguments('{"a": 1}', function_name="test_fn")
1106111061
assert "Repaired" not in caplog.text

0 commit comments

Comments
 (0)