Skip to content

Commit f947140

Browse files
authored
fix: Use asyncio.new_event_loop() to create event loop for tests (#1138)
* fix: Use `asyncio.new_event_loop()` to create event loop for tests Replace the use of `asyncio.get_event_loop()` with more appropriate `asyncio.new_event_loop()` to create event loops for testing. The former used to be a wrapper that either returned the currently running event loop or created a new one, but the latter behavior was deprecated and removed in Python 3.14. Since the tests are always run in a synchronous context, and they always run the obtained event loop to completion, just always create a new event loop. Fixes #1137 Signed-off-by: Michał Górny <[email protected]> * fix: Remove obsolete asgiref pin Remove the `asgiref` pin linked to #1020. I can't reproduce the issue anymore with the current `asgiref` versions, and the pin actually breaks the tests with the `asyncio` event loop fixes. Signed-off-by: Michał Górny <[email protected]> --------- Signed-off-by: Michał Górny <[email protected]>
1 parent b9e78a3 commit f947140

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

tests/test_asgi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ def setUp(self):
4545

4646
def tearDown(self):
4747
if self.communicator:
48-
asyncio.get_event_loop().run_until_complete(
48+
asyncio.new_event_loop().run_until_complete(
4949
self.communicator.wait()
5050
)
5151

5252
def seed_app(self, app):
5353
self.communicator = ApplicationCommunicator(app, self.scope)
5454

5555
def send_input(self, payload):
56-
asyncio.get_event_loop().run_until_complete(
56+
asyncio.new_event_loop().run_until_complete(
5757
self.communicator.send_input(payload)
5858
)
5959

6060
def send_default_request(self):
6161
self.send_input({"type": "http.request", "body": b""})
6262

6363
def get_output(self):
64-
output = asyncio.get_event_loop().run_until_complete(
64+
output = asyncio.new_event_loop().run_until_complete(
6565
self.communicator.receive_output(0)
6666
)
6767
return output
@@ -229,6 +229,6 @@ def test_qs_parsing(self):
229229

230230
self.assert_not_metrics(output, *metrics[i_2])
231231

232-
asyncio.get_event_loop().run_until_complete(
232+
asyncio.new_event_loop().run_until_complete(
233233
self.communicator.wait()
234234
)

tox.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ deps =
88
pytest-benchmark
99
attrs
1010
{py3.9,pypy3.9}: twisted
11-
# NOTE: Pinned due to https://github.com/prometheus/client_python/issues/1020
12-
py3.9: asgiref==3.7
13-
pypy3.9: asgiref==3.7
1411
commands = coverage run --parallel -m pytest {posargs}
1512

1613
[testenv:py3.9-nooptionals]

0 commit comments

Comments
 (0)