Skip to content

Commit 9b63234

Browse files
weiguangli-ioclaude
andcommitted
refactor(test): ensure env cleanup with try-finally block
Applied Gemini Code Assist suggestion to wrap test logic in try-finally, preventing env var leak if test fails. This improves test isolation and prevents flaky tests from state pollution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9231b68 commit 9b63234

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

tests/unittests/cli/utils/test_cli_deploy.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,11 @@ def test_loads_dotenv_before_import(self, tmp_path: Path) -> None:
670670
)
671671
(tmp_path / ".env").write_text("_ADK_TEST_DEPLOY_VAR=from_dotenv\n")
672672

673-
# Should not raise because .env is loaded before import
674-
cli_deploy._validate_agent_import(
675-
str(tmp_path), "root_agent", is_config_agent=False
676-
)
677-
678-
# Clean up the env var
679-
os.environ.pop("_ADK_TEST_DEPLOY_VAR", None)
673+
try:
674+
# Should not raise because .env is loaded before import
675+
cli_deploy._validate_agent_import(
676+
str(tmp_path), "root_agent", is_config_agent=False
677+
)
678+
finally:
679+
# Clean up the env var
680+
os.environ.pop("_ADK_TEST_DEPLOY_VAR", None)

0 commit comments

Comments
 (0)