From 25750005e1e3fd5c9cc1dc2465b6099216bd4104 Mon Sep 17 00:00:00 2001 From: Nathan Herring Date: Sat, 30 May 2026 18:41:02 -0700 Subject: [PATCH] test: restore and fix shadowed test_discovery_http_is_closed During a cleanup of duplicate 'class Discovery(unittest.TestCase)' definitions in tests/test_discovery.py, we discovered that one of the classes was completely dead code because Python silently overwrites classes with identical names in the same module. This shadowed class contained a connection lifecycle test: 'test_discovery_http_is_closed'. This commit deletes the duplicate class and restores the 'test_discovery_http_is_closed' test inside the active Discovery class. The test case has been corrected to use standard 'mock.patch' on 'httplib2.Http' to successfully assert that build() closes the temporary HTTP client used during dynamic discovery initialization, preventing socket leakage. #jetski AI_USAGE=true --- tests/test_discovery.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 2d74ce6dfc..0d5d1daf61 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -495,12 +495,6 @@ def test_ResourceMethodParameters_zoo_animals_patch(self): self.assertEqual(parameters.enum_params, {}) -class Discovery(unittest.TestCase): - def test_discovery_http_is_closed(self): - http = HttpMock(datafile("malformed.json"), {"status": "200"}) - service = build("plus", "v1", credentials=mock.sentinel.credentials) - http.close.assert_called_once() - class DiscoveryErrors(unittest.TestCase): def test_tests_should_be_run_with_strict_positional_enforcement(self): @@ -1535,6 +1529,25 @@ def test_file_based_cache(self): class Discovery(unittest.TestCase): + @mock.patch("httplib2.Http") + def test_discovery_http_is_closed(self, mock_http_class): + discovery_mock_http = mock.Mock() + discovery_mock_http.redirect_codes = set() + service_mock_http = mock.Mock() + service_mock_http.redirect_codes = set() + + discovery_mock_http.request.return_value = ( + httplib2.Response({"status": "200"}), + read_datafile("plus.json"), + ) + + mock_http_class.side_effect = [discovery_mock_http, service_mock_http] + + service = build("plus", "v1", static_discovery=False) + + discovery_mock_http.close.assert_called_once() + service_mock_http.close.assert_not_called() + def test_method_error_checking(self): self.http = HttpMock(datafile("plus.json"), {"status": "200"}) plus = build("plus", "v1", http=self.http, static_discovery=False)