Skip to content

Commit

Permalink
Fix "There is no current event loop" in the asyncio test
Browse files Browse the repository at this point in the history
This bug is causing the test to fail under Python 3.14. Fix it by
calling asyncio.new_event_loop() and asyncio.set_event_loop() as
recommended in: https://stackoverflow.com/a/73367187

Fixes #197
  • Loading branch information
WOnder93 committed Nov 23, 2024
1 parent 278653e commit 17654fb
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions irc/tests/test_client_aio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import asyncio
import contextlib
import warnings
from unittest.mock import MagicMock

from irc import client_aio
Expand All @@ -13,21 +11,14 @@ async def mock_create_connection(*args, **kwargs):
return mock_create_connection


@contextlib.contextmanager
def suppress_issue_197():
with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'There is no current event loop')
yield


def test_privmsg_sends_msg():
# create dummy transport, protocol
mock_transport = MagicMock()
mock_protocol = MagicMock()

# connect to dummy server
with suppress_issue_197():
loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.create_connection = make_mocked_create_connection(
mock_transport, mock_protocol
)
Expand Down

0 comments on commit 17654fb

Please sign in to comment.