Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ASGI tests are failing on Python 3.14 due to missing event loop #1137

Copy link
Copy link
@mgorny

Description

@mgorny
Issue body actions

All of the tests in tests/test_asgi.py are failing with Python 3.14.0rc2:

$ uv pip install -e . pytest asgiref
Resolved 7 packages in 2ms
      Built prometheus-client @ file:///tmp/client_python
Prepared 1 package in 648ms
Installed 7 packages in 9ms
 + asgiref==3.9.1
 + iniconfig==2.1.0
 + packaging==25.0
 + pluggy==1.6.0
 + prometheus-client==0.23.0 (from file:///tmp/client_python)
 + pygments==2.19.2
 + pytest==8.4.2
$ .venv/bin/pytest tests/test_asgi.py -x
========================================================= test session starts =========================================================
platform linux -- Python 3.14.0rc2, pytest-8.4.2, pluggy-1.6.0
rootdir: /tmp/client_python
configfile: pyproject.toml
collected 9 items                                                                                                                     

tests/test_asgi.py FE

=============================================================== ERRORS ================================================================
_______________________________________________ ERROR at teardown of ASGITest.test_gzip _______________________________________________

self = <tests.test_asgi.ASGITest testMethod=test_gzip>

    def tearDown(self):
        if self.communicator:
>           asyncio.get_event_loop().run_until_complete(
            ^^^^^^^^^^^^^^^^^^^^^^^^
                self.communicator.wait()
            )

tests/test_asgi.py:48: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <asyncio.unix_events._UnixDefaultEventLoopPolicy object at 0x7f893e9078c0>

    def get_event_loop(self):
        """Get the event loop for the current context.
    
        Returns an instance of EventLoop or raises an exception.
        """
        if self._local._loop is None:
>           raise RuntimeError('There is no current event loop in thread %r.'
                               % threading.current_thread().name)
E           RuntimeError: There is no current event loop in thread 'MainThread'.

/usr/lib/python3.14/asyncio/events.py:715: RuntimeError
============================================================== FAILURES ===============================================================
_________________________________________________________ ASGITest.test_gzip __________________________________________________________

self = <tests.test_asgi.ASGITest testMethod=test_gzip>

    def test_gzip(self):
        # Increment a metric.
        metric_name = "counter"
        help_text = "A counter"
        increments = 2
        self.increment_metrics(metric_name, help_text, increments)
        app = make_asgi_app(self.registry)
        self.seed_app(app)
        # Send input with gzip header.
        self.scope["headers"] = [(b"accept-encoding", b"gzip")]
>       self.send_input({"type": "http.request", "body": b""})

tests/test_asgi.py:163: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_asgi.py:56: in send_input
    asyncio.get_event_loop().run_until_complete(
    ^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <asyncio.unix_events._UnixDefaultEventLoopPolicy object at 0x7f893e9078c0>

    def get_event_loop(self):
        """Get the event loop for the current context.
    
        Returns an instance of EventLoop or raises an exception.
        """
        if self._local._loop is None:
>           raise RuntimeError('There is no current event loop in thread %r.'
                               % threading.current_thread().name)
E           RuntimeError: There is no current event loop in thread 'MainThread'.

/usr/lib/python3.14/asyncio/events.py:715: RuntimeError
======================================================= short test summary info =======================================================
FAILED tests/test_asgi.py::ASGITest::test_gzip - RuntimeError: There is no current event loop in thread 'MainThread'.
ERROR tests/test_asgi.py::ASGITest::test_gzip - RuntimeError: There is no current event loop in thread 'MainThread'.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 2 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================== 1 failed, 1 error in 0.15s ======================================================

Note that using asyncio.get_event_loop() to create a new event loop was deprecated, and in Python 3.14 it raises an exception instead. FWIU you need to create the event loop yourself (I gues in the setUp() method).

I can reproduce this with 0.23.0.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.