File: replace-more-event-loop-fixture.patch

package info (click to toggle)
aresponses 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 196 kB
  • sloc: python: 713; makefile: 66; sh: 5
file content (86 lines) | stat: -rw-r--r-- 2,645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
From: Colin Watson <cjwatson@debian.org>
Date: Mon, 15 Sep 2025 00:58:14 +0100
Subject: Replace remaining uses of event_loop fixture

The test suite started failing with pytest-asyncio >= 1.0.0, as that
version removed the deprecated `event_loop` fixture.  Finish the work of
replacing it that was started in
https://github.com/aresponses/aresponses/pull/76.

Forwarded: https://github.com/aresponses/aresponses/pull/85
Last-Update: 2025-09-15
---
 README.md                         | 19 ++++++++++++-------
 tests/test_with_aiohttp_client.py | 11 +++++++----
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md
index 7ae2ad5..9cf33fd 100644
--- a/README.md
+++ b/README.md
@@ -179,18 +179,21 @@ async def test_history(aresponses):
 
 #### Context manager usage
 ```python
+import asyncio
+
 import aiohttp
 import pytest
 import aresponses
 
 
 @pytest.mark.asyncio
-async def test_foo(event_loop):
-    async with aresponses.ResponsesMockServer(loop=event_loop) as arsps:
+async def test_foo():
+    loop = asyncio.get_running_loop()
+    async with aresponses.ResponsesMockServer(loop=loop) as arsps:
         arsps.add('foo.com', '/', 'get', 'hi there!!')
         arsps.add(arsps.ANY, '/', 'get', arsps.Response(text='hey!'))
         
-        async with aiohttp.ClientSession(loop=event_loop) as session:
+        async with aiohttp.ClientSession(loop=loop) as session:
             async with session.get('http://foo.com') as response:
                 text = await response.text()
                 assert text == 'hi'
@@ -216,10 +219,12 @@ async def aresponses(loop):
 If you're trying to use the `aiohttp_client` test fixture then you'll need to mock out the aiohttp `loop` fixture
 instead:
 ```python
-@pytest.fixture
-def loop(event_loop):
-    """replace aiohttp loop fixture with pytest-asyncio fixture"""
-    return event_loop
+import pytest_asyncio
+
+@pytest_asyncio.fixture
+async def loop():
+    """Replace aiohttp loop fixture."""
+    return asyncio.get_running_loop()
 ```
 
 ## Contributing
diff --git a/tests/test_with_aiohttp_client.py b/tests/test_with_aiohttp_client.py
index b7b0847..064d6fc 100644
--- a/tests/test_with_aiohttp_client.py
+++ b/tests/test_with_aiohttp_client.py
@@ -1,12 +1,15 @@
+import asyncio
+
 import aiohttp
 import pytest
+import pytest_asyncio
 from aiohttp import web
 
 
-@pytest.fixture()
-def loop(event_loop):
-    """replace aiohttp loop fixture with pytest-asyncio fixture"""
-    return event_loop
+@pytest_asyncio.fixture()
+async def loop():
+    """Replace aiohttp loop fixture."""
+    return asyncio.get_running_loop()
 
 
 def make_app():