async pytest fails, when MultiDeviceTestContext started with process=True
I found nontrivial bug: if you create async test, when MultiDeviceTestContext used with process=True parameter, then it fails with RuntimeError: Loop is already running
. If we start it with process=False - everything works
This is the simplest example:
import pytest
from tango import GreenMode
from tango.server import Device
from tango.test_context import MultiDeviceTestContext
class TestDevice(Device):
green_mode = GreenMode.Asyncio
config = ({"class": TestDevice, "devices": [{"name": "test/device/1"}]},)
@pytest.mark.asyncio
async def test_async_context():
with MultiDeviceTestContext(config, process=True):
pass
PS the same happens if you do the following:
import asyncio
from tango import GreenMode
from tango.server import Device
from tango.test_context import MultiDeviceTestContext
class TestDevice(Device):
green_mode = GreenMode.Asyncio
config = ({"class": TestDevice, "devices": [{"name": "test/device/1"}]},)
async def main_loop():
with MultiDeviceTestContext(config, process=True):
pass
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main_loop())
loop.close()
Edited by Yury Matveyev