From c6ac6b50e998876543a2f167f126ff064c29ec16 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:16:49 +0000 Subject: [PATCH] fix(tests): use targeted settings mock instead of broad getattr patch Replace module-level getattr patch with a MagicMock that has a property raising on google_drive_use_oauth access, as suggested by code review. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/test_api_google_drive_coverage2.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_api_google_drive_coverage2.py b/tests/test_api_google_drive_coverage2.py index 10631e1b..f6f1b97c 100644 --- a/tests/test_api_google_drive_coverage2.py +++ b/tests/test_api_google_drive_coverage2.py @@ -118,7 +118,11 @@ class TestGetTokenInfoOuterException: def test_get_token_info_outer_exception(self, client: TestClient): """Trigger the outer exception handler in get_google_drive_token_info.""" - with patch("app.api.google_drive.getattr", side_effect=Exception("boom")): + mock_settings = MagicMock() + # Property on the mock type so getattr() propagates a non-AttributeError, + # bypassing the default value and reaching the outer except block. + type(mock_settings).google_drive_use_oauth = property(lambda self: (_ for _ in ()).throw(Exception("boom"))) + with patch("app.api.google_drive.settings", mock_settings): response = client.get("/api/google-drive/get-token-info") assert response.status_code == 200