Skip to content

Commit 9998c23

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 24b014a commit 9998c23

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
@@ -56,7 +56,6 @@ dev-dependencies = [
5656
"dirty-equals>=0.6.0",
5757
"importlib-metadata>=6.7.0",
5858
"rich>=13.7.1",
59-
"nest_asyncio==1.6.0",
6059
"pytest-xdist>=3.6.1",
6160
]
6261

requirements-dev.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ multidict==6.4.4
7575
mypy==1.14.1
7676
mypy-extensions==1.0.0
7777
# via mypy
78-
nest-asyncio==1.6.0
7978
nodeenv==1.8.0
8079
# via pyright
8180
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,6 +20,7 @@
2320

2421
from llama_api_client import LlamaAPIClient, AsyncLlamaAPIClient, APIResponseValidationError
2522
from llama_api_client._types import Omit
23+
from llama_api_client._utils import asyncify
2624
from llama_api_client._models import BaseModel, FinalRequestOptions
2725
from llama_api_client._exceptions import (
2826
APIStatusError,
@@ -34,8 +32,10 @@
3432
DEFAULT_TIMEOUT,
3533
HTTPX_DEFAULT_TIMEOUT,
3634
BaseClient,
35+
OtherPlatform,
3736
DefaultHttpxClient,
3837
DefaultAsyncHttpxClient,
38+
get_platform,
3939
make_request_options,
4040
)
4141

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

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

1731-
def test_get_platform(self) -> None:
1732-
# A previous implementation of asyncify could leave threads unterminated when
1733-
# used with nest_asyncio.
1734-
#
1735-
# Since nest_asyncio.apply() is global and cannot be un-applied, this
1736-
# test is run in a separate process to avoid affecting other tests.
1737-
test_code = dedent("""
1738-
import asyncio
1739-
import nest_asyncio
1740-
import threading
1741-
1742-
from llama_api_client._utils import asyncify
1743-
from llama_api_client._base_client import get_platform
1744-
1745-
async def test_main() -> None:
1746-
result = await asyncify(get_platform)()
1747-
print(result)
1748-
for thread in threading.enumerate():
1749-
print(thread.name)
1750-
1751-
nest_asyncio.apply()
1752-
asyncio.run(test_main())
1753-
""")
1754-
with subprocess.Popen(
1755-
[sys.executable, "-c", test_code],
1756-
text=True,
1757-
) as process:
1758-
timeout = 10 # seconds
1759-
1760-
start_time = time.monotonic()
1761-
while True:
1762-
return_code = process.poll()
1763-
if return_code is not None:
1764-
if return_code != 0:
1765-
raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
1766-
1767-
# success
1768-
break
1769-
1770-
if time.monotonic() - start_time > timeout:
1771-
process.kill()
1772-
raise AssertionError("calling get_platform using asyncify resulted in a hung process")
1773-
1774-
time.sleep(0.1)
1731+
async def test_get_platform(self) -> None:
1732+
platform = await asyncify(get_platform)()
1733+
assert isinstance(platform, (str, OtherPlatform))
17751734

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

0 commit comments

Comments
 (0)