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
When running a pytest that uses aioresponse to mock the calls using verion 3.9.0 I get an error: object mock can't be used in await expression
when running the same code in version 3.8.5 everything is working
Traceback (most recent call last):
File "<string>", line 19, in func_wrapper
File "/Users/nimrodmilo/dev/web_consumer/web_consumer/data_extraction/web_crawling/instant_branding.py", line 142, in get_profile_image
social_data = await get_social_link_data(
File "/Users/nimrodmilo/dev/web_consumer/web_consumer/data_extraction/scrapping/social.py", line 40, in get_social_link_data
return ans
File "/Users/nimrodmilo/Library/Caches/pypoetry/virtualenvs/web-consumer-HhfrqN_r-py3.9/lib/python3.9/site-packages/aiohttp/client.py", line 1206, in __aexit__
await self._resp.wait_for_close()
File "/Users/nimrodmilo/Library/Caches/pypoetry/virtualenvs/web-consumer-HhfrqN_r-py3.9/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1096, in wait_for_close
await self._writer
TypeError: object Mock can't be used in 'await' expression
aioresponses version = 0.7.5
To Reproduce
install aiohttp==3.9.0, and aioresponse==0.7.5
run the following code:
import pytest
from aioresponses import aioresponses
from urllib.parse import quote_plus
@pytest.mark.asyncio
async def test_http_requests():
# Setup for aioresponses to mock external API calls
with aioresponses() as mock_aioresponse:
mock_url = "http://mockapi.com/get_data"
mock_response_data = {"key": "value"}
# Mocking a GET request
mock_aioresponse.get(
mock_url,
payload=mock_response_data
)
# Using aiohttp.ClientSession to make an actual request
async with aiohttp.ClientSession() as session:
async with session.get(mock_url) as response:
result = await response.json()
# Assert to check if the response matches the mocked data
assert result == mock_response_data
Expected behavior
test should run
Logs/tracebacks
test_instant_branding.py::test_http_requests FAILED [100%]
test_instant_branding.py:178 (test_http_requests)
@pytest.mark.asyncio
asyncdeftest_http_requests():
# Setup for aioresponses to mock external API callswith aioresponses() as mock_aioresponse:
mock_url ="http://mockapi.com/get_data"
mock_response_data = {"key": "value"}
# Mocking a GET request
mock_aioresponse.get(
mock_url,
payload=mock_response_data
)
# Using aiohttp.ClientSession to make an actual requestasyncwith aiohttp.ClientSession() as session:
asyncwith session.get(mock_url) as response:
> result = await response.json()
test_instant_branding.py:195:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Users/nimrodmilo/Library/Caches/pypoetry/virtualenvs/web-consumer-HhfrqN_r-py3.9/lib/python3.9/site-packages/aiohttp/client_reqrep.py:1161: in json
awaitself.read()
/Users/nimrodmilo/Library/Caches/pypoetry/virtualenvs/web-consumer-HhfrqN_r-py3.9/lib/python3.9/site-packages/aiohttp/client_reqrep.py:1114: in read
awaitself._wait_released() # Underlying connection released
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ClientResponse(http://mockapi.com/get_data) [200 OK]>
<CIMultiDict('Content-Type': 'application/json')>asyncdef_wait_released(self) -> None:
ifself._writer isnotNone:
> await self._writer
E TypeError: object Mock can't be used in 'await' expression
/Users/nimrodmilo/Library/Caches/pypoetry/virtualenvs/web-consumer-HhfrqN_r-py3.9/lib/python3.9/site-packages/aiohttp/client_reqrep.py:1080: TypeError
During handling of the above exception, another exception occurred:
@pytest.mark.asyncio
asyncdeftest_http_requests():
# Setup for aioresponses to mock external API callswith aioresponses() as mock_aioresponse:
mock_url ="http://mockapi.com/get_data"
mock_response_data = {"key": "value"}
# Mocking a GET request
mock_aioresponse.get(
mock_url,
payload=mock_response_data
)
# Using aiohttp.ClientSession to make an actual requestasyncwith aiohttp.ClientSession() as session:
asyncwith session.get(mock_url) as response:
result =await response.json()
# Assert to check if the response matches the mocked data
> assert result == mock_response_data
test_instant_branding.py:198:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Users/nimrodmilo/Library/Caches/pypoetry/virtualenvs/web-consumer-HhfrqN_r-py3.9/lib/python3.9/site-packages/aiohttp/client.py:1206: in __aexit__
awaitself._resp.wait_for_close()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ClientResponse(http://mockapi.com/get_data) [200 OK]>
<CIMultiDict('Content-Type': 'application/json')>asyncdefwait_for_close(self) -> None:
ifself._writer isnotNone:
> await self._writer
E TypeError: object Mock can't be used in 'await' expression
/Users/nimrodmilo/Library/Caches/pypoetry/virtualenvs/web-consumer-HhfrqN_r-py3.9/lib/python3.9/site-packages/aiohttp/client_reqrep.py:1096: TypeError
Describe the bug
When running a pytest that uses aioresponse to mock the calls using verion 3.9.0 I get an error:
object mock can't be used in await expression
when running the same code in version 3.8.5 everything is working
aioresponses version = 0.7.5
To Reproduce
Expected behavior
test should run
Logs/tracebacks
Python Version
3.9.16
aiohttp Version
3.9.0
multidict Version
yarl Version
OS
mac OS
Related component
Client
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: