Skip to content

Commit 30194f1

Browse files
chore(internal): test updates (#1602)
1 parent d50550b commit 30194f1

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Diff for: src/openai/_utils/_reflection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def assert_signatures_in_sync(
3434

3535
if custom_param.annotation != source_param.annotation:
3636
errors.append(
37-
f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(source_param.annotation)}"
37+
f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(custom_param.annotation)}"
3838
)
3939
continue
4040

Diff for: tests/test_client.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pydantic import ValidationError
1818

1919
from openai import OpenAI, AsyncOpenAI, APIResponseValidationError
20+
from openai._types import Omit
2021
from openai._models import BaseModel, FinalRequestOptions
2122
from openai._constants import RAW_RESPONSE_HEADER
2223
from openai._streaming import Stream, AsyncStream
@@ -328,7 +329,8 @@ def test_validate_headers(self) -> None:
328329
assert request.headers.get("Authorization") == f"Bearer {api_key}"
329330

330331
with pytest.raises(OpenAIError):
331-
client2 = OpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
332+
with update_env(**{"OPENAI_API_KEY": Omit()}):
333+
client2 = OpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
332334
_ = client2
333335

334336
def test_default_query_option(self) -> None:
@@ -1103,7 +1105,8 @@ def test_validate_headers(self) -> None:
11031105
assert request.headers.get("Authorization") == f"Bearer {api_key}"
11041106

11051107
with pytest.raises(OpenAIError):
1106-
client2 = AsyncOpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
1108+
with update_env(**{"OPENAI_API_KEY": Omit()}):
1109+
client2 = AsyncOpenAI(base_url=base_url, api_key=None, _strict_response_validation=True)
11071110
_ = client2
11081111

11091112
def test_default_query_option(self) -> None:

Diff for: tests/utils.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import date, datetime
99
from typing_extensions import Literal, get_args, get_origin, assert_type
1010

11-
from openai._types import NoneType
11+
from openai._types import Omit, NoneType
1212
from openai._utils import (
1313
is_dict,
1414
is_list,
@@ -139,11 +139,15 @@ def _assert_list_type(type_: type[object], value: object) -> None:
139139

140140

141141
@contextlib.contextmanager
142-
def update_env(**new_env: str) -> Iterator[None]:
142+
def update_env(**new_env: str | Omit) -> Iterator[None]:
143143
old = os.environ.copy()
144144

145145
try:
146-
os.environ.update(new_env)
146+
for name, value in new_env.items():
147+
if isinstance(value, Omit):
148+
os.environ.pop(name, None)
149+
else:
150+
os.environ[name] = value
147151

148152
yield None
149153
finally:

0 commit comments

Comments
 (0)