Conversation
…ttp_is_closed tests/test_discovery.py defined class Discovery(unittest.TestCase) twice: once near line 498 (added in googleapis#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.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request refactors and relocates the test_discovery_http_is_closed test in tests/test_discovery.py to use @mock.patch for mocking httplib2.Http instead of relying on HttpMock. The feedback suggests two improvements: first, to mock the response content as bytes by reading the datafile with 'rb' to better align with Python 3 behavior; second, to use a mock with a proper spec for credentials instead of a generic MagicMock to ensure type-checking compatibility.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Fixes #2757.
tests/test_discovery.pydefinedclass Discovery(unittest.TestCase)twice: once near line 498 (added in #1038 to test thatbuild()closes thehttplib2.Httpit creates internally) and once further down (pre-existing). In Python, the second class definition silently overwrites the first at import time, sotest_discovery_http_is_closedwas never collected by pytest and has been dead code since 2020.The dead test was also broken on its own terms:
HttpMock.closeis a plain method, not a mock object, so calling.assert_called_once()on it raisesAttributeErrorrather than testing anything — confirmed by isolating and running it directly.Fix
Removes the duplicate class and moves a corrected version of the test into the real
Discoveryclass, patchinghttplib2.Httpdirectly so the assertion actually exercises the close-the-internal-http-client behavior indiscovery.py(thediscovery_http.close()call made whenbuild()creates its ownhttpclient to fetch the discovery document).Verified the new test both passes against current code and fails (as expected) if that
discovery_http.close()call is removed.Test plan
pytest tests/test_discovery.py— 167 passed (up from 166), same 5 pre-existing unrelated failures (credentials/cache/mtls tests that fail in this sandboxed environment regardless of this change).black --checkclean.