Repository navigation
test: restore has_aiohttp after every client test - #3345
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
copybara/1018426778
branch
2 times, most recently
from
November 10, 2026 23:22
a8ddd20 to
8f83127
Compare
has_aiohttp after client tests that override ithas_aiohttp after every client test
copybara-service
Bot
force-pushed
the
copybara/1018426778
branch
2 times, most recently
from
November 12, 2026 02:34
b354403 to
815c7cc
Compare
`test_custom_client.py`, `test_client_close.py` and `test_aiohttp_retries.py` set the module-level `_api_client.has_aiohttp` flag but never restored it. When `aiohttp` is not installed, `test_constructor_with_httpx_clients` left the flag at `True`, so async uploads in later tests on the same pytest-xdist worker took the aiohttp path and failed with `NameError: name 'aiohttp' is not defined` (for example `tests/gaos/test_environments_lifecycle.py::test_python_environments_async_file_upload_download`). Which tests shared a worker depended on how many tests were collected, so the failure came and went with unrelated changes. Replace the per-file `reset_has_aiohttp` fixtures with a single autouse fixture in `tests/client/conftest.py`. It saves the original value and restores it after every client test. The old fixtures in `test_async_stream.py`, `test_client_initialization.py` and `test_retries.py` forced the flag to `False` instead, which turned aiohttp off for later tests when it is installed. Two tests depended on that forced `False` without setting it. `test_client_initializes_httpx_clients_vertex_and_mldev` and `test_vertexai_with_httpx2` now set `has_aiohttp = False` themselves. Also fix `test_constructor_with_httpx_clients`, which checked `_use_aiohttp()` on the Gemini Developer API client twice and never on the Vertex AI client. PiperOrigin-RevId: 1019680062
copybara-service
Bot
force-pushed
the
copybara/1018426778
branch
from
November 12, 2026 02:50
815c7cc to
6f6dc5d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test: restore
has_aiohttpafter every client testtest_custom_client.py,test_client_close.pyandtest_aiohttp_retries.pyset the module-level_api_client.has_aiohttpflag but never restored it. Whenaiohttpis not installed,test_constructor_with_httpx_clientsleft the flag atTrue, so async uploads in later tests on the same pytest-xdist worker took the aiohttp path and failed withNameError: name 'aiohttp' is not defined(for exampletests/gaos/test_environments_lifecycle.py::test_python_environments_async_file_upload_download). Which tests shared a worker depended on how many tests were collected, so the failure came and went with unrelated changes.Replace the per-file
reset_has_aiohttpfixtures with a single autouse fixture intests/client/conftest.py. It saves the original value and restores it after every client test. The old fixtures intest_async_stream.py,test_client_initialization.pyandtest_retries.pyforced the flag toFalseinstead, which turned aiohttp off for later tests when it is installed.Two tests depended on that forced
Falsewithout setting it.test_client_initializes_httpx_clients_vertex_and_mldevandtest_vertexai_with_httpx2now sethas_aiohttp = Falsethemselves.Also fix
test_constructor_with_httpx_clients, which checked_use_aiohttp()on the Gemini Developer API client twice and never on the Vertex AI client.