From d25250ba7aeebd06ad49871bf4b87da0efd6333b Mon Sep 17 00:00:00 2001 From: Tatamis <80774326+Tatamis@users.noreply.github.com> Date: Thu, 17 Sep 2026 13:54:38 +0300 Subject: [PATCH 1/3] test: remove duplicate Discovery class that shadowed test_discovery_http_is_closed tests/test_discovery.py defined class Discovery(unittest.TestCase) twice: once near line 498 (added in #1038 to test that build() closes the httplib2.Http it creates internally) and once near line 1544 (pre-existing). The second definition silently overwrote the first, so test_discovery_http_is_closed was never collected by pytest and had been dead code since 2020. The dead test was also broken on its own terms: HttpMock.close is a plain method, not a mock, so calling .assert_called_once() on it raises AttributeError rather than testing anything. Move a corrected version of the test into the real Discovery class, patching httplib2.Http directly so the assertion exercises the actual close-the-internal-http-client behavior in discovery.py. --- tests/test_discovery.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 6912783451..9c3f4e9a43 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -495,13 +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): try: @@ -1549,6 +1542,21 @@ def test_file_based_cache(self): class Discovery(unittest.TestCase): + @mock.patch("httplib2.Http") + def test_discovery_http_is_closed(self, mock_http_class): + mock_http = mock_http_class.return_value + mock_http.request.return_value = ( + httplib2.Response({"status": "200"}), + read_datafile("plus.json"), + ) + build( + "plus", + "v1", + credentials=mock.MagicMock(), + static_discovery=False, + ) + mock_http.close.assert_called_once() + def test_method_error_checking(self): self.http = HttpMock(datafile("plus.json"), {"status": "200"}) plus = build("plus", "v1", http=self.http, static_discovery=False) From 0b935e0e695ecb7e3693d6cdaeaebbb28cfe2c27 Mon Sep 17 00:00:00 2001 From: Tatamis <80774326+Tatamis@users.noreply.github.com> Date: Thu, 17 Sep 2026 13:57:12 +0300 Subject: [PATCH 2/3] Update tests/test_discovery.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- tests/test_discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 9c3f4e9a43..f78f425b38 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -1547,7 +1547,7 @@ def test_discovery_http_is_closed(self, mock_http_class): mock_http = mock_http_class.return_value mock_http.request.return_value = ( httplib2.Response({"status": "200"}), - read_datafile("plus.json"), + read_datafile("plus.json", "rb"), ) build( "plus", From a09ab7fa24bf9cf55f30cfd6852e33bf3743e05a Mon Sep 17 00:00:00 2001 From: Tatamis <80774326+Tatamis@users.noreply.github.com> Date: Thu, 17 Sep 2026 13:57:23 +0300 Subject: [PATCH 3/3] Update tests/test_discovery.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- tests/test_discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index f78f425b38..87324d8761 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -1552,7 +1552,7 @@ def test_discovery_http_is_closed(self, mock_http_class): build( "plus", "v1", - credentials=mock.MagicMock(), + credentials=mock.Mock(spec=google.auth.credentials.Credentials), static_discovery=False, ) mock_http.close.assert_called_once()