Skip to content

Commit 6421017

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 3bdf24e commit 6421017

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
@@ -57,7 +57,6 @@ dev-dependencies = [
5757
"dirty-equals>=0.6.0",
5858
"importlib-metadata>=6.7.0",
5959
"rich>=13.7.1",
60-
"nest_asyncio==1.6.0",
6160
"pytest-xdist>=3.6.1",
6261
"python-dotenv",
6362
"playwright",

requirements-dev.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ multidict==6.6.4
8888
mypy==1.14.1
8989
mypy-extensions==1.0.0
9090
# via mypy
91-
nest-asyncio==1.6.0
9291
nodeenv==1.9.1
9392
# via pyright
9493
nox==2024.10.9

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 browserbase import Browserbase, AsyncBrowserbase, APIResponseValidationError
2522
from browserbase._types import Omit
23+
from browserbase._utils import asyncify
2624
from browserbase._models import BaseModel, FinalRequestOptions
2725
from browserbase._exceptions import APIStatusError, APITimeoutError, BrowserbaseError, APIResponseValidationError
2826
from browserbase._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

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

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

1650-
def test_get_platform(self) -> None:
1651-
# A previous implementation of asyncify could leave threads unterminated when
1652-
# used with nest_asyncio.
1653-
#
1654-
# Since nest_asyncio.apply() is global and cannot be un-applied, this
1655-
# test is run in a separate process to avoid affecting other tests.
1656-
test_code = dedent("""
1657-
import asyncio
1658-
import nest_asyncio
1659-
import threading
1660-
1661-
from browserbase._utils import asyncify
1662-
from browserbase._base_client import get_platform
1663-
1664-
async def test_main() -> None:
1665-
result = await asyncify(get_platform)()
1666-
print(result)
1667-
for thread in threading.enumerate():
1668-
print(thread.name)
1669-
1670-
nest_asyncio.apply()
1671-
asyncio.run(test_main())
1672-
""")
1673-
with subprocess.Popen(
1674-
[sys.executable, "-c", test_code],
1675-
text=True,
1676-
) as process:
1677-
timeout = 10 # seconds
1678-
1679-
start_time = time.monotonic()
1680-
while True:
1681-
return_code = process.poll()
1682-
if return_code is not None:
1683-
if return_code != 0:
1684-
raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code")
1685-
1686-
# success
1687-
break
1688-
1689-
if time.monotonic() - start_time > timeout:
1690-
process.kill()
1691-
raise AssertionError("calling get_platform using asyncify resulted in a hung process")
1692-
1693-
time.sleep(0.1)
1650+
async def test_get_platform(self) -> None:
1651+
platform = await asyncify(get_platform)()
1652+
assert isinstance(platform, (str, OtherPlatform))
16941653

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

0 commit comments

Comments
 (0)