From c8649ec7b5679282ed516ee4484c8a9b27c6a6db Mon Sep 17 00:00:00 2001 From: reginaldalfret Date: Thu, 29 Oct 2026 07:00:33 +0530 Subject: [PATCH] test: restore shadowed discovery http close test Resolve #2757 by removing the duplicate class Discovery(unittest.TestCase) definition at line 498 which was shadowed by the active definition at line 1551. In the active Discovery test suite, reinstate test_discovery_http_is_closed with proper mock patching for build_http(), and add test_provided_http_is_not_closed to verify caller-provided HTTP instances are not closed. Signed-off-by: reginaldalfret --- tests/test_discovery.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 6912783451..ca37c6ed7d 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,19 @@ def test_file_based_cache(self): class Discovery(unittest.TestCase): + @mock.patch("googleapiclient.discovery.build_http") + def test_discovery_http_is_closed(self, mock_build_http): + mock_http = mock.Mock() + mock_build_http.return_value = mock_http + creds = mock.Mock() + service = build("youtube", "v3", credentials=creds) + mock_http.close.assert_called_once() + + def test_provided_http_is_not_closed(self): + provided_http = mock.Mock() + service = build("youtube", "v3", http=provided_http) + provided_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)