Skip to content

fix: Use asyncio.new_event_loop() to create event loop for tests - #1138

Merged
csmarchbanks merged 2 commits into
prometheus:masterfrom
mgorny:asyncio-tests
Sep 12, 2025
Merged

csmarchbanks merged 2 commits into
prometheus:masterfrom
mgorny:asyncio-tests

Conversation

@mgorny

@mgorny mgorny commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

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

mgorny commented Sep 12, 2025

Copy link
Copy Markdown
Contributor Author

@csmarchbanks

@csmarchbanks

Copy link
Copy Markdown
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

mgorny commented Sep 13, 2025

Copy link
Copy Markdown
Contributor Author

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