Skip to content

[PY] Some unit tests are conditional upon the existence of GEMINI_API_KEY. #2988

@yesudeep

Description

@yesudeep

Describe the bug
Tests fail with:

=================================== short test summary info ===================================
FAILED plugins/google-genai/test/test_google_plugin.py::TestGoogleAIInit::test_init_raises_value_error_no_api_key - AssertionError: ValueError not raised
FAILED plugins/google-genai/test/test_google_plugin.py::TestGoogleAIInit::test_init_with_credentials - AssertionError: expected call not found.
Expected: Client(vertexai=False, api_key=None, credentials=<MagicMock spec='Credentials' id='NNNNNNNNN'>, debug_config=None, http_options=HttpOptions(base_url=None, api_version=None, headers={'x-goog-api-client': 'genkit-python/0.3.2', 'user-agent': 'genkit-python/0.3.2'}, timeout=None, client_args=None, async_client_args=None))
Actual: Client(vertexai=False, api_key='XXXXXXXXXXXXXXXXXXXXXX', credentials=<MagicMock spec='Credentials' id='NNNNNNNNN'>, debug_config=None, http_options=HttpOptions(base_url=None, api_version=None, headers={'x-goog-api-client': 'genkit-python/0.3.2', 'user-agent': 'genkit-python/0.3.2'}, timeout=None, client_args=None, async_client_args=None))

pytest introspection follows:

Kwargs:
assert {'vertexai': False, 'api_key': 'XXXXXXXXXXXXXXXXXXXXXX', 'credentials': <MagicMock spec='Credentials' id='NNNNNNNNN'>, 'debug_config': None, 'http_options': HttpOptions(base_url=None, api_version=None, headers={'x-goog-api-client': 'genkit-python/0.3.2', 'user-agent': 'genkit-python/0.3.2'}, timeout=None, client_args=None, async_client_args=None)} == {'vertexai': False, 'api_key': None, 'credentials': <MagicMock spec='Credentials' id='NNNNNNNNN'>, 'debug_config': None, 'http_options': HttpOptions(base_url=None, api_version=None, headers={'x-goog-api-client': 'genkit-python/0.3.2', 'user-agent': 'genkit-python/0.3.2'}, timeout=None, client_args=None, async_client_args=None)}

  Common items:
  {'credentials': <MagicMock spec='Credentials' id='NNNNNNNNN'>,
   'debug_config': None,
   'http_options': HttpOptions(base_url=None, api_version=None, headers={'x-goog-api-client': 'genkit-python/0.3.2', 'user-agent': 'genkit-python/0.3.2'}, timeout=None, client_args=None, async_client_args=None),
   'vertexai': False}
  Differing items:
  {'api_key': 'XXXXXXXXXXXXXXXXXXXXXX'} != {'api_key': None}

  Full diff:
    {
  -     'api_key': None,
  +     'api_key': 'XXXXXXXXXXXXXXXXXXXXXX',
        'credentials': <MagicMock spec='Credentials' id='NNNNNNNNN'>,
        'debug_config': None,
        'http_options': HttpOptions(base_url=None, api_version=None, headers={'x-goog-api-client': 'genkit-python/0.3.2', 'user-agent': 'genkit-python/0.3.2'}, timeout=None, client_args=None, async_client_args=None),
        'vertexai': False,
    }
========================= 2 failed, 346 passed, 13 warnings in 12.50s =========================

To Reproduce

  1. Define the GEMINI_API_KEY environment variable with an API key value.

  2. Tests fail.

  3. Unset the GEMINI_API_KEY environment variable.

  4. Tests pass.

Expected behavior
Tests should cover both cases (environment variable defined and undefined).

Screenshots
If applicable, add screenshots to help explain your problem.

Runtime (please complete the following information):

  • OS: macOS
  • Genkit Version HEAD

Python version

zsh❯ uv run python --version
Python 3.12.8

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpythonPython

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions