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 unit testing handler/middleware behavior with a request created via make_mocked_request() method without specifying payload, ran into issues with reading its content inside handler.
Looking at the source, found problem with the an default empty mock that is assigned if payload is not explicitly specified.
To Reproduce
Run the following sample minimal script that reproduces the behavior.
When running as web_app, the request to / sends 200.
When running via test, it fails. Ideally the payload should be initialized as empty so that if awaited, empty body is returned inside handler.
Logs/tracebacks
❯ python3 main.py
Traceback (most recent call last):
File "/test-app/main.py", line 19, in <module>
asyncio.run(test())
File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in runreturn loop.run_until_complete(main)
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_completereturn future.result()
File "/test-app/main.py", line 11, in testawait handle(req)
File "/test-app/main.py", line 6, in handle
request_body =await request.read()
File "/test-app/venv/lib/python3.10/site-packages/aiohttp/web_request.py", line 649, in read
chunk =awaitself._payload.readany()
TypeError: object Mock can't be used in 'await' expression
rahulnht
changed the title
[make_mocked_request()] behavior is broken when no payload is specified
make_mocked_request() behavior is broken when no payload is specified
Jan 13, 2023
Describe the bug
When unit testing handler/middleware behavior with a request created via make_mocked_request() method without specifying payload, ran into issues with reading its content inside handler.
Looking at the source, found problem with the an default empty mock that is assigned if payload is not explicitly specified.
To Reproduce
Run the following sample minimal script that reproduces the behavior.
Expected behavior
When running as web_app, the request to / sends 200.
When running via test, it fails. Ideally the payload should be initialized as empty so that if awaited, empty body is returned inside handler.
Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
Ubuntu 22.04.1
Related component
Server
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: