Skip to content

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Sep 12, 2025

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

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 prometheus#1137

Signed-off-by: Michał Górny <mgorny@gentoo.org>
Remove the `asgiref` pin linked to prometheus#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 <mgorny@gentoo.org>
@mgorny
Copy link
Contributor Author

mgorny commented Sep 12, 2025

@csmarchbanks

@csmarchbanks
Copy link
Member

Thank you!

@csmarchbanks csmarchbanks merged commit f947140 into prometheus:master Sep 12, 2025
11 checks passed
@mgorny mgorny deleted the asyncio-tests branch September 13, 2025 04:31
@mgorny
Copy link
Contributor Author

mgorny commented Sep 13, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASGI tests are failing on Python 3.14 due to missing event loop
2 participants