From 87538d23503f68f5c77ceca09d43cae0d21329cb Mon Sep 17 00:00:00 2001 From: "Wei (Jack) Sun" Date: Thu, 11 Jun 2026 17:27:14 -0700 Subject: [PATCH] test: Suppress experimental feature warnings in unit tests Merge https://github.com/google/adk-python/pull/6087 ## Summary - Unit tests instantiate many `@experimental`-decorated classes, flooding test output with `[EXPERIMENTAL]` `UserWarning` messages. - Set `ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS=true` in `tests/unittests/conftest.py` (alongside the existing `ADK_ALLOW_WIP_FEATURES`) to silence them session-wide. - The four `*_no_parens` / `*_empty_parens` decorator tests that assert the warning fires now `monkeypatch.delenv` the suppress var first, matching the pattern already used by their sibling tests, so they remain valid under the new default. ## Test plan - [x] `uv run pytest tests/unittests/utils/test_feature_decorator.py tests/unittests/features/test_feature_decorator.py` passes - [x] Verified a real `@experimental` class (`InMemoryCredentialService`) emits 0 `[EXPERIMENTAL]` warnings with the var set, 2 without Co-authored-by: Wei Sun (Jack) COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/6087 from google:test/suppress-experimental-warnings 23c43d9188fe33529b41d08325eb1c41ac5dddd6 PiperOrigin-RevId: 930824931 --- tests/unittests/conftest.py | 1 + .../unittests/utils/test_feature_decorator.py | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/unittests/conftest.py b/tests/unittests/conftest.py index ced12d25..bfcf9b15 100644 --- a/tests/unittests/conftest.py +++ b/tests/unittests/conftest.py @@ -28,6 +28,7 @@ _ENV_VARS = { 'GOOGLE_CLOUD_PROJECT': 'fake_google_cloud_project', 'GOOGLE_CLOUD_LOCATION': 'fake_google_cloud_location', 'ADK_ALLOW_WIP_FEATURES': 'true', + 'ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS': 'true', } ENV_SETUPS = { diff --git a/tests/unittests/utils/test_feature_decorator.py b/tests/unittests/utils/test_feature_decorator.py index 68c1e5ae..8e32fff0 100644 --- a/tests/unittests/utils/test_feature_decorator.py +++ b/tests/unittests/utils/test_feature_decorator.py @@ -306,8 +306,11 @@ def test_experimental_class_not_bypassed_for_false_env_var(monkeypatch): assert "[EXPERIMENTAL] ExperimentalClass:" in str(w[0].message) -def test_experimental_class_no_parens_warns(): +def test_experimental_class_no_parens_warns(monkeypatch): """Test that experimental class without parentheses shows default warning.""" + monkeypatch.delenv( + "ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS", raising=False + ) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") @@ -323,8 +326,11 @@ def test_experimental_class_no_parens_warns(): ) -def test_experimental_class_empty_parens_warns(): +def test_experimental_class_empty_parens_warns(monkeypatch): """Test that experimental class with empty parentheses shows default warning.""" + monkeypatch.delenv( + "ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS", raising=False + ) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") @@ -340,8 +346,11 @@ def test_experimental_class_empty_parens_warns(): ) -def test_experimental_function_no_parens_warns(): +def test_experimental_function_no_parens_warns(monkeypatch): """Test that experimental function without parentheses shows default warning.""" + monkeypatch.delenv( + "ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS", raising=False + ) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") @@ -356,8 +365,11 @@ def test_experimental_function_no_parens_warns(): ) -def test_experimental_function_empty_parens_warns(): +def test_experimental_function_empty_parens_warns(monkeypatch): """Test that experimental function with empty parentheses shows default warning.""" + monkeypatch.delenv( + "ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS", raising=False + ) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always")