You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior/code LRSHTTP.status() and all other methods should work when called inside an async function.
Actual Behavior
As reported openfun/warren#44 (comment) , the LRSHTTP methods returns an error when called within an events loop. The problem is caused by nesting of asyncio.get_event_loop().run_until_complete(...), which is not allowed.
Steps to Reproduce
Add and run test:
import asyncio
from unittest.mock import AsyncMock
import pytest
from ralph.backends.http.async_lrs import AsyncLRSHTTP, HTTPBackendStatus
from ralph.backends.http.lrs import LRSHTTP
@pytest.mark.anyio
async def test_backend_http_lrs_in_async_setting(monkeypatch):
"""Test that backend works when run in async function."""
async def async_function():
lrs = LRSHTTP()
status_mock_response = HTTPBackendStatus.OK
status_mock = AsyncMock(return_value=status_mock_response)
monkeypatch.setattr(AsyncLRSHTTP, "status", status_mock)
assert lrs.status() == status_mock_response
await async_function()
Possible Solution
The first answer of this post suggest to use nest-asyncio.
The text was updated successfully, but these errors were encountered:
Leobouloc
changed the title
(backend) LRSHTTP is not working properly when run inside an Async function.
(backend) LRSHTTP methods return an error when run inside an Async function.
Jul 26, 2023
Leobouloc
changed the title
(backend) LRSHTTP methods return an error when run inside an Async function.
(backend) LRSHTTP methods return an error when run inside an asynchroneous function.
Jul 26, 2023
Leobouloc
changed the title
(backend) LRSHTTP methods return an error when run inside an asynchroneous function.
🐛(backend) LRSHTTP methods return an error when run inside an asynchroneous function.
Jul 26, 2023
Bug Report
Expected behavior/code
LRSHTTP.status()
and all other methods should work when called inside an async function.Actual Behavior
As reported openfun/warren#44 (comment) , the
LRSHTTP
methods returns an error when called within an events loop. The problem is caused by nesting ofasyncio.get_event_loop().run_until_complete(...)
, which is not allowed.Steps to Reproduce
Add and run test:
Results in:
Environment
Possible Solution
The first answer of this post suggest to use
nest-asyncio
.The text was updated successfully, but these errors were encountered: