mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 09:25:14 +03:00
chore(openai): fix tests (#39972)
This commit is contained in:
1 parent
8fa38dc143
commit
4fe9d3062f
4 files changed
+38
-8
No files matched your search
@@ -737,7 +737,9 @@ jobs:
|
||||
# Run tests
|
||||
uv sync --group test --group test_integration
|
||||
uv pip install $PRERELEASE_FLAG ../../core/dist/*.whl
|
||||
make test
|
||||
|
||||
env -u LANGSMITH_GATEWAY -u LANGSMITH_GATEWAY_API_KEY -u OPENAI_API_KEY make test
|
||||
|
||||
make integration_tests
|
||||
|
||||
# Test external packages that depend on langchain-core/langchain against the new release
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Shared fixtures for `langchain-openai` unit tests."""
|
||||
|
||||
import pytest
|
||||
|
||||
# Set by CI (and by developers routing local traffic through the LangSmith
|
||||
# gateway). `ChatOpenAI` resolves these at construction time and swaps in the
|
||||
# gateway base URL and key, which flips `_uses_gateway` and diverts mocked
|
||||
# clients down the `with_raw_response` path.
|
||||
_GATEWAY_VARS = (
|
||||
"LANGSMITH_GATEWAY",
|
||||
"LANGSMITH_GATEWAY_API_KEY",
|
||||
"LANGSMITH_API_KEY",
|
||||
)
|
||||
|
||||
_PROVIDER_VARS = (
|
||||
"OPENAI_BASE_URL",
|
||||
"OPENAI_API_BASE",
|
||||
"OPENAI_ORG_ID",
|
||||
"OPENAI_ORGANIZATION",
|
||||
"OPENAI_PROXY",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def hermetic_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Isolate unit tests from ambient OpenAI and gateway configuration.
|
||||
|
||||
Unit tests run offline against mocked clients, so any real credential or
|
||||
base URL in the environment can only change behavior for the worse. Tests
|
||||
that exercise environment handling override these with their own
|
||||
`monkeypatch` calls, which still take precedence.
|
||||
"""
|
||||
for var in (*_GATEWAY_VARS, *_PROVIDER_VARS):
|
||||
monkeypatch.delenv(var, raising=False)
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "foo")
|
||||
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
@@ -7,8 +6,6 @@ from pydantic import SecretStr
|
||||
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "foo"
|
||||
|
||||
|
||||
def test_openai_invalid_model_kwargs() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from langchain_core.outputs import GenerationChunk
|
||||
|
||||
from langchain_openai import OpenAI
|
||||
from langchain_openai.llms.base import _stream_response_to_generation_chunk
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "foo"
|
||||
|
||||
OPENAI_LLM_TEST_MODEL = "gpt-3.5-turbo-instruct"
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user