Skip to content

Commit e33fd61

Browse files
committed
Merge branch 'master' into drop-pytest-plugin
2 parents fc9bcf1 + 129ef25 commit e33fd61

17 files changed

Lines changed: 207 additions & 327 deletions

docs/testing.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ basis, the TestClient object can be used directly::
517517
A full list of the utilities provided can be found at the
518518
:data:`api reference <aiohttp.test_utils>`
519519

520+
For end-to-end client code that talks to an external service, it is
521+
recommended to run a small fake server rather than patching private aiohttp
522+
internals. The ``examples/fake_server.py`` demo shows such an approach: start
523+
a local :class:`~aiohttp.web.Application`, point a custom resolver at it, and
524+
exercise the client against that controlled endpoint.
525+
520526

521527
Testing API Reference
522528
---------------------

requirements/constraints.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ exceptiongroup==1.3.1
7474
# via pytest
7575
execnet==2.1.2
7676
# via pytest-xdist
77-
filelock==3.28.0
77+
filelock==3.29.0
7878
# via
7979
# python-discovery
8080
# virtualenv
@@ -91,7 +91,7 @@ frozenlist==1.8.0
9191
# aiosignal
9292
gunicorn==25.3.0
9393
# via -r requirements/base.in
94-
identify==2.6.18
94+
identify==2.6.19
9595
# via pre-commit
9696
idna==3.11
9797
# via

requirements/dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ exceptiongroup==1.3.1
7272
# via pytest
7373
execnet==2.1.2
7474
# via pytest-xdist
75-
filelock==3.28.0
75+
filelock==3.29.0
7676
# via
7777
# python-discovery
7878
# virtualenv
@@ -89,7 +89,7 @@ frozenlist==1.8.0
8989
# aiosignal
9090
gunicorn==25.3.0
9191
# via -r requirements/base.in
92-
identify==2.6.18
92+
identify==2.6.19
9393
# via pre-commit
9494
idna==3.11
9595
# via

requirements/lint.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ distlib==0.4.0
3535
# via virtualenv
3636
exceptiongroup==1.3.1
3737
# via pytest
38-
filelock==3.28.0
38+
filelock==3.29.0
3939
# via
4040
# python-discovery
4141
# virtualenv
4242
forbiddenfruit==0.1.4
4343
# via blockbuster
4444
freezegun==1.5.5
4545
# via -r requirements/lint.in
46-
identify==2.6.18
46+
identify==2.6.19
4747
# via pre-commit
4848
idna==3.11
4949
# via trustme

tests/test_client_proto.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
from aiohttp.http_parser import HttpParser, RawResponseMessage
1414

1515

16-
def test_force_close(event_loop: asyncio.AbstractEventLoop) -> None:
16+
async def test_force_close() -> None:
1717
"""Ensure that the force_close method sets the should_close attribute to True.
1818
1919
This is used externally in aiodocker
2020
https://github.com/aio-libs/aiodocker/issues/920
2121
"""
22-
proto = ResponseHandler(loop=event_loop)
22+
proto = ResponseHandler(loop=asyncio.get_running_loop())
2323
proto.force_close()
2424
assert proto.should_close
2525

2626

27-
def test_oserror(event_loop: asyncio.AbstractEventLoop) -> None:
28-
proto = ResponseHandler(loop=event_loop)
27+
async def test_oserror() -> None:
28+
proto = ResponseHandler(loop=asyncio.get_running_loop())
2929
transport = mock.Mock()
3030
proto.connection_made(transport)
3131
proto.connection_lost(OSError())
@@ -34,9 +34,9 @@ def test_oserror(event_loop: asyncio.AbstractEventLoop) -> None:
3434
assert isinstance(proto.exception(), ClientOSError)
3535

3636

37-
async def test_pause_resume_on_error(event_loop: asyncio.AbstractEventLoop) -> None:
37+
async def test_pause_resume_on_error() -> None:
3838
parser = mock.create_autospec(HttpParser, spec_set=True, instance=True)
39-
proto = ResponseHandler(loop=event_loop)
39+
proto = ResponseHandler(loop=asyncio.get_running_loop())
4040
proto._parser = parser
4141
transport = mock.Mock()
4242
proto.connection_made(transport)
@@ -48,8 +48,8 @@ async def test_pause_resume_on_error(event_loop: asyncio.AbstractEventLoop) -> N
4848
assert not proto._reading_paused
4949

5050

51-
def test_client_proto_bad_message(event_loop: asyncio.AbstractEventLoop) -> None:
52-
proto = ResponseHandler(loop=event_loop)
51+
async def test_client_proto_bad_message() -> None:
52+
proto = ResponseHandler(loop=asyncio.get_running_loop())
5353
transport = mock.Mock()
5454
proto.connection_made(transport)
5555
proto.set_response_params()
@@ -60,8 +60,8 @@ def test_client_proto_bad_message(event_loop: asyncio.AbstractEventLoop) -> None
6060
assert isinstance(proto.exception(), http.HttpProcessingError)
6161

6262

63-
def test_uncompleted_message(event_loop: asyncio.AbstractEventLoop) -> None:
64-
proto = ResponseHandler(loop=event_loop)
63+
async def test_uncompleted_message() -> None:
64+
proto = ResponseHandler(loop=asyncio.get_running_loop())
6565
transport = mock.Mock()
6666
proto.connection_made(transport)
6767
proto.set_response_params(read_until_eof=True)
@@ -78,8 +78,8 @@ def test_uncompleted_message(event_loop: asyncio.AbstractEventLoop) -> None:
7878
assert dict(exc.message.headers) == {"Location": "http://python.org/"}
7979

8080

81-
def test_data_received_after_close(event_loop: asyncio.AbstractEventLoop) -> None:
82-
proto = ResponseHandler(loop=event_loop)
81+
async def test_data_received_after_close() -> None:
82+
proto = ResponseHandler(loop=asyncio.get_running_loop())
8383
transport = mock.Mock()
8484
proto.connection_made(transport)
8585
proto.set_response_params(read_until_eof=True)
@@ -202,32 +202,32 @@ async def test_client_protocol_readuntil_eof() -> None:
202202
assert response.content.is_eof()
203203

204204

205-
def test_empty_data(event_loop: asyncio.AbstractEventLoop) -> None:
206-
proto = ResponseHandler(loop=event_loop)
205+
async def test_empty_data() -> None:
206+
proto = ResponseHandler(loop=asyncio.get_running_loop())
207207
proto.data_received(b"")
208208

209209
# do nothing
210210

211211

212-
def test_schedule_timeout(event_loop: asyncio.AbstractEventLoop) -> None:
213-
proto = ResponseHandler(loop=event_loop)
212+
async def test_schedule_timeout() -> None:
213+
proto = ResponseHandler(loop=asyncio.get_running_loop())
214214
proto.set_response_params(read_timeout=1)
215215
assert proto._read_timeout_handle is None
216216
proto.start_timeout()
217217
assert proto._read_timeout_handle is not None
218218

219219

220-
def test_drop_timeout(event_loop: asyncio.AbstractEventLoop) -> None:
221-
proto = ResponseHandler(loop=event_loop)
220+
async def test_drop_timeout() -> None:
221+
proto = ResponseHandler(loop=asyncio.get_running_loop())
222222
proto.set_response_params(read_timeout=1)
223223
proto.start_timeout()
224224
assert proto._read_timeout_handle is not None
225225
proto._drop_timeout()
226226
assert proto._read_timeout_handle is None
227227

228228

229-
def test_reschedule_timeout(event_loop: asyncio.AbstractEventLoop) -> None:
230-
proto = ResponseHandler(loop=event_loop)
229+
async def test_reschedule_timeout() -> None:
230+
proto = ResponseHandler(loop=asyncio.get_running_loop())
231231
proto.set_response_params(read_timeout=1)
232232
proto.start_timeout()
233233
assert proto._read_timeout_handle is not None
@@ -237,23 +237,21 @@ def test_reschedule_timeout(event_loop: asyncio.AbstractEventLoop) -> None:
237237
assert proto._read_timeout_handle is not h
238238

239239

240-
def test_eof_received(event_loop: asyncio.AbstractEventLoop) -> None:
241-
proto = ResponseHandler(loop=event_loop)
240+
async def test_eof_received() -> None:
241+
proto = ResponseHandler(loop=asyncio.get_running_loop())
242242
proto.set_response_params(read_timeout=1)
243243
proto.start_timeout()
244244
assert proto._read_timeout_handle is not None
245245
proto.eof_received()
246246
assert proto._read_timeout_handle is None
247247

248248

249-
def test_connection_lost_sets_transport_to_none(
250-
event_loop: asyncio.AbstractEventLoop, mocker: MockerFixture
251-
) -> None:
249+
async def test_connection_lost_sets_transport_to_none(mocker: MockerFixture) -> None:
252250
"""Ensure that the transport is set to None when the connection is lost.
253251
254252
This ensures the writer knows that the connection is closed.
255253
"""
256-
proto = ResponseHandler(loop=event_loop)
254+
proto = ResponseHandler(loop=asyncio.get_running_loop())
257255
proto.connection_made(mocker.Mock())
258256
assert proto.transport is not None
259257

0 commit comments

Comments
 (0)