Skip to content

Commit f192889

Browse files
chore(internal): bump pytest to v8 & pydantic (#1829)
1 parent c403ef3 commit f192889

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

requirements-dev.lock

+9-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ anyio==4.4.0
1616
# via openai
1717
argcomplete==3.1.2
1818
# via nox
19-
attrs==23.1.0
20-
# via pytest
2119
certifi==2023.7.22
2220
# via httpcore
2321
# via httpx
@@ -28,8 +26,9 @@ distlib==0.3.7
2826
# via virtualenv
2927
distro==1.8.0
3028
# via openai
31-
exceptiongroup==1.1.3
29+
exceptiongroup==1.2.2
3230
# via anyio
31+
# via pytest
3332
filelock==3.12.4
3433
# via virtualenv
3534
h11==0.14.0
@@ -60,20 +59,18 @@ packaging==23.2
6059
# via pytest
6160
platformdirs==3.11.0
6261
# via virtualenv
63-
pluggy==1.3.0
64-
# via pytest
65-
py==1.11.0
62+
pluggy==1.5.0
6663
# via pytest
67-
pydantic==2.7.1
64+
pydantic==2.9.2
6865
# via openai
69-
pydantic-core==2.18.2
66+
pydantic-core==2.23.4
7067
# via pydantic
7168
pygments==2.18.0
7269
# via rich
7370
pyright==1.1.380
74-
pytest==7.1.1
71+
pytest==8.3.3
7572
# via pytest-asyncio
76-
pytest-asyncio==0.21.1
73+
pytest-asyncio==0.24.0
7774
python-dateutil==2.8.2
7875
# via time-machine
7976
pytz==2023.3.post1
@@ -90,10 +87,10 @@ sniffio==1.3.0
9087
# via httpx
9188
# via openai
9289
time-machine==2.9.0
93-
tomli==2.0.1
90+
tomli==2.0.2
9491
# via mypy
9592
# via pytest
96-
typing-extensions==4.8.0
93+
typing-extensions==4.12.2
9794
# via anyio
9895
# via mypy
9996
# via openai

requirements.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ certifi==2023.7.22
1919
# via httpx
2020
distro==1.8.0
2121
# via openai
22-
exceptiongroup==1.1.3
22+
exceptiongroup==1.2.2
2323
# via anyio
2424
h11==0.14.0
2525
# via httpcore
@@ -30,15 +30,15 @@ httpx==0.25.2
3030
idna==3.4
3131
# via anyio
3232
# via httpx
33-
pydantic==2.7.1
33+
pydantic==2.9.2
3434
# via openai
35-
pydantic-core==2.18.2
35+
pydantic-core==2.23.4
3636
# via pydantic
3737
sniffio==1.3.0
3838
# via anyio
3939
# via httpx
4040
# via openai
41-
typing-extensions==4.8.0
41+
typing-extensions==4.12.2
4242
# via anyio
4343
# via openai
4444
# via pydantic

src/openai/_compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
133133
def model_dump(
134134
model: pydantic.BaseModel,
135135
*,
136-
exclude: IncEx = None,
136+
exclude: IncEx | None = None,
137137
exclude_unset: bool = False,
138138
exclude_defaults: bool = False,
139139
warnings: bool = True,

src/openai/_models.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __str__(self) -> str:
176176
# Based on https://github.com/samuelcolvin/pydantic/issues/1168#issuecomment-817742836.
177177
@classmethod
178178
@override
179-
def construct(
179+
def construct( # pyright: ignore[reportIncompatibleMethodOverride]
180180
cls: Type[ModelT],
181181
_fields_set: set[str] | None = None,
182182
**values: object,
@@ -248,8 +248,8 @@ def model_dump(
248248
self,
249249
*,
250250
mode: Literal["json", "python"] | str = "python",
251-
include: IncEx = None,
252-
exclude: IncEx = None,
251+
include: IncEx | None = None,
252+
exclude: IncEx | None = None,
253253
by_alias: bool = False,
254254
exclude_unset: bool = False,
255255
exclude_defaults: bool = False,
@@ -303,8 +303,8 @@ def model_dump_json(
303303
self,
304304
*,
305305
indent: int | None = None,
306-
include: IncEx = None,
307-
exclude: IncEx = None,
306+
include: IncEx | None = None,
307+
exclude: IncEx | None = None,
308308
by_alias: bool = False,
309309
exclude_unset: bool = False,
310310
exclude_defaults: bool = False,

src/openai/_types.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Optional,
1717
Sequence,
1818
)
19-
from typing_extensions import Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable
19+
from typing_extensions import Set, Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable
2020

2121
import httpx
2222
import pydantic
@@ -195,7 +195,9 @@ def get(self, __key: str) -> str | None: ...
195195

196196
# Note: copied from Pydantic
197197
# https://github.com/pydantic/pydantic/blob/32ea570bf96e84234d2992e1ddf40ab8a565925a/pydantic/main.py#L49
198-
IncEx: TypeAlias = "set[int] | set[str] | dict[int, Any] | dict[str, Any] | None"
198+
IncEx: TypeAlias = Union[
199+
Set[int], Set[str], Mapping[int, Union["IncEx", Literal[True]]], Mapping[str, Union["IncEx", Literal[True]]]
200+
]
199201

200202
PostParser = Callable[[Any], Any]
201203

tests/conftest.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
import os
4-
import asyncio
54
import logging
65
from typing import TYPE_CHECKING, Iterator, AsyncIterator
76

87
import pytest
8+
from pytest_asyncio import is_async_test
99

1010
from openai import OpenAI, AsyncOpenAI
1111

@@ -17,11 +17,13 @@
1717
logging.getLogger("openai").setLevel(logging.DEBUG)
1818

1919

20-
@pytest.fixture(scope="session")
21-
def event_loop() -> Iterator[asyncio.AbstractEventLoop]:
22-
loop = asyncio.new_event_loop()
23-
yield loop
24-
loop.close()
20+
# automatically add `pytest.mark.asyncio()` to all of our async tests
21+
# so we don't have to add that boilerplate everywhere
22+
def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:
23+
pytest_asyncio_tests = (item for item in items if is_async_test(item))
24+
session_scope_marker = pytest.mark.asyncio(loop_scope="session")
25+
for async_test in pytest_asyncio_tests:
26+
async_test.add_marker(session_scope_marker, append=False)
2527

2628

2729
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")

0 commit comments

Comments
 (0)