From 3ae443a65fa36cc23ce10526bf9501b213d24fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Fri, 12 Sep 2025 19:59:58 +0200 Subject: [PATCH 1/2] fix: Use `asyncio.new_event_loop()` to create event loop for tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/test_asgi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_asgi.py b/tests/test_asgi.py index 386ff598..86431d21 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -45,7 +45,7 @@ def setUp(self): def tearDown(self): if self.communicator: - asyncio.get_event_loop().run_until_complete( + asyncio.new_event_loop().run_until_complete( self.communicator.wait() ) @@ -53,7 +53,7 @@ def seed_app(self, app): self.communicator = ApplicationCommunicator(app, self.scope) def send_input(self, payload): - asyncio.get_event_loop().run_until_complete( + asyncio.new_event_loop().run_until_complete( self.communicator.send_input(payload) ) @@ -61,7 +61,7 @@ def send_default_request(self): self.send_input({"type": "http.request", "body": b""}) def get_output(self): - output = asyncio.get_event_loop().run_until_complete( + output = asyncio.new_event_loop().run_until_complete( self.communicator.receive_output(0) ) return output @@ -229,6 +229,6 @@ def test_qs_parsing(self): self.assert_not_metrics(output, *metrics[i_2]) - asyncio.get_event_loop().run_until_complete( + asyncio.new_event_loop().run_until_complete( self.communicator.wait() ) From 454e19dc5155aee44132f3414d93d97095488a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Fri, 12 Sep 2025 20:32:57 +0200 Subject: [PATCH 2/2] fix: Remove obsolete asgiref pin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tox.ini | 3 --- 1 file changed, 3 deletions(-) diff --git a/tox.ini b/tox.ini index bef57f85..40337027 100644 --- a/tox.ini +++ b/tox.ini @@ -8,9 +8,6 @@ deps = pytest-benchmark attrs {py3.9,pypy3.9}: twisted - # NOTE: Pinned due to https://github.com/prometheus/client_python/issues/1020 - py3.9: asgiref==3.7 - pypy3.9: asgiref==3.7 commands = coverage run --parallel -m pytest {posargs} [testenv:py3.9-nooptionals]