From 55d2789c952b206fb6f22bcaebb4bd50e077f1a3 Mon Sep 17 00:00:00 2001 From: Stepan Shamaiev <59963936+skippdot@users.noreply.github.com> Date: Tue, 1 Sep 2026 13:18:55 +0300 Subject: [PATCH] fix: restore shadowed test_discovery_http_is_closed test - Remove the duplicate `class Discovery(unittest.TestCase)` definition that has shadowed the active class of the same name since 2020, leaving its only test permanently uncollected by the test runner - Re-add `test_discovery_http_is_closed` inside the surviving class, rewritten to patch `httplib2.Http`: the original asserted on `HttpMock.close`, a plain method that would raise AttributeError if the test ever ran - Pass `cache_discovery=False` so the discovery document is always fetched through the mocked client and the close assertion cannot be bypassed by a cache hit; the test fails if `build()` stops closing its temporary client Fixes #2757 --- tests/test_discovery.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 6912783451..02a496730a 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,20 @@ def test_file_based_cache(self): class Discovery(unittest.TestCase): + @mock.patch("httplib2.Http") + def test_discovery_http_is_closed(self, http_class): + discovery_http = http_class.return_value + discovery_http.request.return_value = ( + httplib2.Response({"status": "200"}), + read_datafile("plus.json", "rb"), + ) + + build("plus", "v1", cache_discovery=False, static_discovery=False) + + # build() creates a temporary http client to fetch the discovery + # document and must close it so the connection is not leaked. + discovery_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)