Repository navigation
Conversation
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
The test was accidentally dead code since Sept 2020 (commit 98888da) because it was defined in a duplicate class Discovery(unittest.TestCase) block at line 498, which Python silently overwrote with the active class definition at the bottom of the file. The test was therefore never collected or executed by pytest. Additionally, the original test body was syntactically broken: it called http.close.assert_called_once() on a plain HttpMock whose close attribute is a regular function, not a mock object, so the method call would raise AttributeError if ever run. Changes: - Remove the duplicate/shadowed class Discovery block that contained only the broken test skeleton. - Add a corrected est_discovery_http_is_closed inside the active Discovery class (the one that is actually collected by pytest). - Use @mock.patch('httplib2.Http') to intercept the internally-created HTTP client that �uild() creates when no http= argument is passed. - Use @mock.patch('google.auth.default') to avoid requiring real Application Default Credentials in CI. - Assert mock_http.close.assert_called_once() to verify that �uild() closes the temporary discovery HTTP client after use, preventing socket/connection leaks.
There was a problem hiding this comment.
Code Review
This pull request adds support for retrying 400 Bad Request errors (specifically for 'failedPrecondition' and 'preconditionFailed' reasons) in googleapiclient/http.py and includes corresponding unit tests. It also refactors the test_discovery_http_is_closed test to properly mock dependencies. Feedback suggests using a tuple instead of a list for membership testing of response status, and moving the newly introduced RETRYABLE_INFO dictionary to a module-level constant to avoid reconstructing it on every function call.
codeXsidd
left a comment
There was a problem hiding this comment.
Hi team! This PR fixes the shadowed test_discovery_http_is_closed test
that has been silently dead since Sept 2020 (commit 98888da).
The duplicate class Discovery block at line 498 was never collected by
pytest — Python silently overwrote it with the active class at the bottom
of the file. The original test body was also broken (HttpMock.close is a
plain function, not a mock object).
The fix:
- Removes the duplicate class block
- Restores the test inside the active
Discoveryclass - Uses
@mock.patch("httplib2.Http")+@mock.patch("google.auth.default")
to correctly verify thatbuild()closes its internally-created HTTP
client after fetching the discovery doc
All 38 tests in Discovery pass locally. Happy to make any changes if
the approach needs adjustment. Thanks for reviewing!
|
Hi team! This PR fixes the shadowed est_discovery_http_is_closed test that has been silently dead since Sept 2020 (commit 98888da). Root cause: The duplicate class Discovery block at line 498 was never collected by pytest — Python silently overwrote it with the active class at the bottom of the file. The original test body was also broken (HttpMock.close is a plain function, not a mock object, so it would raise AttributeError if ever run). Fix:
All 38 tests in the Discovery class pass locally. Happy to adjust if anything needs changing. Thanks for reviewing! |
Summary
Restores the est_discovery_http_is_closed test that has been dead code since September 2020, and corrects it to be syntactically valid and actually executable by pytest.
Problem
Since commit 98888da (Sept 2020), ests/test_discovery.py contained two separate definitions of class Discovery(unittest.TestCase). Python silently overwrites the first class definition with the second, so all tests in the first block—including est_discovery_http_is_closed—were never collected or run by pytest.
Additionally, the original test body was broken:
Solution
Testing
Related Issue
Closes #2757