From f865475f9f07318e92f575f31b21bd24fea1c9ae Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Wed, 31 Jul 2024 18:30:34 +0200 Subject: [PATCH] tests/test_ethernetport: create and set event loop for test Calling asyncio.get_event_loop() with no current event loop is deprecated since Python 3.10 and will be an error in some future Python release [1]. SNMPEthernetPort expects a running event loop. So create and set one. [1] https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop Signed-off-by: Bastian Krause --- tests/test_ethernetport.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_ethernetport.py b/tests/test_ethernetport.py index bea4b8ad7..55dbac6b8 100644 --- a/tests/test_ethernetport.py +++ b/tests/test_ethernetport.py @@ -1,6 +1,15 @@ +import asyncio + from labgrid.resource import SNMPEthernetPort def test_instance(target): - s = SNMPEthernetPort(target, 'port-1', switch='dummy-switch', interface='1') - assert (isinstance(s, SNMPEthernetPort)) + # SNMPEthernetPort should be called with a running event loop + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + try: + s = SNMPEthernetPort(target, 'port-1', switch='dummy-switch', interface='1') + assert (isinstance(s, SNMPEthernetPort)) + finally: + loop.close()