Skip to content

Commit

Permalink
Fix sleep fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
MtkN1 committed May 12, 2024
1 parent c6df6da commit a98cbda
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ def dummy_request(method: str, str_or_url: StrOrURL, **kwargs):
await clients.pop().close()


@pytest.fixture
def sleep_cancel(monkeypatch):
async def sleep_canceller(delay):
raise asyncio.CancelledError()

monkeypatch.setattr(asyncio, asyncio.sleep.__name__, sleep_canceller)


async def create_access_token(request: web.Request):
return web.json_response(
{
Expand Down Expand Up @@ -137,13 +129,16 @@ async def extend_access_token_error(request: web.Request):
],
)
async def test_gmo_manage_ws_token(
pybotters_client: Callable[..., Awaitable[pybotters.Client]],
base_url: str,
extend_access_handler: Callable[..., Awaitable[web.Response]],
create_access_handler: Callable[..., Awaitable[web.Response]],
pybotters_client: Callable[..., Awaitable[pybotters.Client]],
base_url: str,
expected_token: str,
sleep_cancel: None,
monkeypatch: pytest.MonkeyPatch,
):
async def sleep_canceller(delay):
raise asyncio.CancelledError()

app = web.Application()
app.router.add_put("/private/v1/ws-auth", extend_access_handler)
app.router.add_post("/private/v1/ws-auth", create_access_handler)
Expand All @@ -155,7 +150,8 @@ async def test_gmo_manage_ws_token(
m_ws.url = url

helper = GMOCoinHelper(client)
with suppress(asyncio.CancelledError):
with monkeypatch.context() as m, suppress(asyncio.CancelledError):
m.setattr(asyncio, asyncio.sleep.__name__, sleep_canceller)
await helper.manage_ws_token(
m_ws,
token,
Expand Down

0 comments on commit a98cbda

Please sign in to comment.