Skip to content

Commit d30a165

Browse files
chore(tests): simplify get_platform test
`nest_asyncio` is archived and broken on some platforms so it's not worth keeping in our test suite.
1 parent 49b32b4 commit d30a165

File tree

3 files changed

+6
-49
lines changed

3 files changed

+6
-49
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ dev-dependencies = [
6262
"dirty-equals>=0.6.0",
6363
"importlib-metadata>=6.7.0",
6464
"rich>=13.7.1",
65-
"nest_asyncio==1.6.0",
6665
"pytest-xdist>=3.6.1",
6766
]
6867

requirements-dev.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ multidict==6.5.0
7777
mypy==1.14.1
7878
mypy-extensions==1.0.0
7979
# via mypy
80-
nest-asyncio==1.6.0
8180
nodeenv==1.8.0
8281
# via pyright
8382
nox==2023.4.22

tests/test_client.py

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
import os
77
import sys
88
import json
9-
import time
109
import asyncio
1110
import inspect
12-
import subprocess
1311
import tracemalloc
1412
from typing import Any, Union, cast
15-
from textwrap import dedent
1613
from unittest import mock
1714
from typing_extensions import Literal
1815

@@ -23,14 +20,17 @@
2320

2421
from openlayer import Openlayer, AsyncOpenlayer, APIResponseValidationError
2522
from openlayer._types import Omit
23+
from openlayer._utils import asyncify
2624
from openlayer._models import BaseModel, FinalRequestOptions
2725
from openlayer._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
2826
from openlayer._base_client import (
2927
DEFAULT_TIMEOUT,
3028
HTTPX_DEFAULT_TIMEOUT,
3129
BaseClient,
30+
OtherPlatform,
3231
DefaultHttpxClient,
3332
DefaultAsyncHttpxClient,
33+
get_platform,
3434
make_request_options,
3535
)
3636

@@ -1791,50 +1791,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
17911791

17921792
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
17931793

1794-
def test_get_platform(self) -> None:
1795-
# A previous implementation of asyncify could leave threads unterminated when
1796-
# used with nest_asyncio.
1797-
#
1798-
# Since nest_asyncio.apply() is global and cannot be un-applied, this
1799-
# test is run in a separate process to avoid affecting other tests.
1800-
test_code = dedent("""
1801-
import asyncio
1802-
import nest_asyncio
1803-
import threading
1804-
1805-
from openlayer._utils import asyncify
1806-
from openlayer._base_client import get_platform
1807-
1808-
async def test_main() -> None:
1809-
result = await asyncify(get_platform)()
1810-
print(result)
1811-
for thread in threading.enumerate():
1812-
print(thread.name)
1813-
1814-
nest_asyncio.apply()
1815-
asyncio.run(test_main())
1816-
""")
1817-
with subprocess.Popen(
1818-
[sys.executable, "-c", test_code],
1819-
text=True,
1820-
) as process:
1821-
timeout = 10 # seconds
1822-
1823-
start_time = time.monotonic()
1824-
while True:
1825-
return_code = process.poll()
1826-
if return_code is not None:
1827-
if return_code != 0:
1828-
raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
1829-
1830-
# success
1831-
break
1832-
1833-
if time.monotonic() - start_time > timeout:
1834-
process.kill()
1835-
raise AssertionError("calling get_platform using asyncify resulted in a hung process")
1836-
1837-
time.sleep(0.1)
1794+
async def test_get_platform(self) -> None:
1795+
platform = await asyncify(get_platform)()
1796+
assert isinstance(platform, (str, OtherPlatform))
18381797

18391798
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
18401799
# Test that the proxy environment variables are set correctly

0 commit comments

Comments
 (0)