mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-27 18:45:05 +08:00
🐛 Bug: 添加 HTTP 客户端会话上下文检查 (#2632)
This commit is contained in:
parent
7a232c7a4a
commit
9b4b1526b1
@ -124,6 +124,8 @@ class Session(HTTPClientSession):
|
||||
|
||||
@override
|
||||
async def setup(self) -> None:
|
||||
if self._client is not None:
|
||||
raise RuntimeError("Session has already been initialized")
|
||||
self._client = aiohttp.ClientSession(
|
||||
cookies=self._cookies,
|
||||
headers=self._headers,
|
||||
|
@ -93,6 +93,8 @@ class Session(HTTPClientSession):
|
||||
|
||||
@override
|
||||
async def setup(self) -> None:
|
||||
if self._client is not None:
|
||||
raise RuntimeError("Session has already been initialized")
|
||||
self._client = httpx.AsyncClient(
|
||||
params=self._params,
|
||||
headers=self._headers,
|
||||
|
@ -328,6 +328,11 @@ async def test_http_client_session(driver: Driver, server_url: URL):
|
||||
with pytest.raises(RuntimeError):
|
||||
await session.request(request)
|
||||
|
||||
with pytest.raises(RuntimeError): # noqa: PT012
|
||||
async with session:
|
||||
async with session:
|
||||
...
|
||||
|
||||
async with session as session:
|
||||
# simple post with query, headers, cookies and content
|
||||
request = Request(
|
||||
|
Loading…
Reference in New Issue
Block a user