Skip to content

test: restore has_aiohttp after every client test - #3345

Merged
copybara-service[bot] merged 1 commit into
mainfrom
copybara/1018426778
Nov 12, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
copybara/1018426778

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

test: restore has_aiohttp after every client test

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.

@copybara-service
copybara-service Bot force-pushed the copybara/1018426778 branch 2 times, most recently from a8ddd20 to 8f83127 Compare November 10, 2026 23:22
@copybara-service copybara-service Bot changed the title test: restore has_aiohttp after client tests that override it test: restore has_aiohttp after every client test Nov 10, 2026
@copybara-service
copybara-service Bot force-pushed the copybara/1018426778 branch 2 times, most recently from b354403 to 815c7cc Compare November 12, 2026 02:34
`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
copybara-service Bot merged commit 6f6dc5d into main Nov 12, 2026
1 check passed
@copybara-service
copybara-service Bot deleted the copybara/1018426778 branch November 12, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant