Fix tests: replace deprecated asyncio.get_event_loop() for Python 3.12+#1748
Merged
AlexxIT merged 3 commits intoMar 2, 2026
Merged
Conversation
asyncio.get_event_loop() no longer auto-creates an event loop in Python 3.12+ and raises RuntimeError in 3.14. Replaced with asyncio.new_event_loop() + asyncio.set_event_loop() in: - tests/__init__.py: DummyRegistry.call() - tests/test_entity.py: await_() - tests/test_misc.py: test_bulk()
Changed asyncio.create_task mock from discarding coroutines to properly closing them, eliminating RuntimeWarning about unawaited coroutines.
AlexxIT
added a commit
to Antonio112009/SonoffLAN
that referenced
this pull request
Mar 2, 2026
AlexxIT
force-pushed
the
fix/tests-asyncio-event-loop
branch
from
March 2, 2026 13:02
94d8062 to
fd3c3ab
Compare
AlexxIT
approved these changes
Mar 2, 2026
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
asyncio.get_event_loop()no longer auto-creates an event loop in Python 3.12+ and raisesRuntimeErrorin Python 3.14. This causedtest_light_group,test_light_22,test_1394, andtest_bulkto fail.Additionally, the
asyncio.create_taskmock in test setup discarded coroutines without closing them, producingRuntimeWarning: coroutine was never awaitedwarnings.Changes
tests/__init__.pyDummyRegistry.call(): replacedasyncio.get_event_loop()withasyncio.new_event_loop()+asyncio.set_event_loop()init(): changedasyncio.create_task = lambda _: Nonetolambda coro: coro.close()to properly close discarded coroutines and eliminate warningstests/test_entity.pyawait_(): replacedasyncio.get_event_loop()withasyncio.new_event_loop()+asyncio.set_event_loop()tests/test_misc.pytest_bulk(): replacedasyncio.get_event_loop()withasyncio.new_event_loop()+asyncio.set_event_loop()Result
HomeAssistantApplication)