Closed TECH7Fox closed 1 year ago
I wonder if using pytest_asyncio
asyncio_mode = auto
is actually mandatory with how the plugin works. See #129. This is the readme as being maybe required
, but if https://github.com/TECH7Fox/asterisk-hass-integration/pull/76 works, then I will update the readme here accordingly.
Thanks for helping! With asyncio_mode = auto
it's still the same problem.
From your PR CI:
=========================== short test summary info ============================
FAILED tests/test_sensors.py::test_connected_line_sensor - RuntimeError: Event loop is closed
FAILED tests/test_sensors.py::test_dtmf_sent_sensor - RuntimeError: Event loop is closed
FAILED tests/test_sensors.py::test_dtmf_received_sensor - RuntimeError: Event loop is closed
=================== 3 failed, 3 passed, 3 warnings in 1.11s ====================
sys:1: RuntimeWarning: coroutine 'Entity.async_update_ha_state' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Sorry I'm out of any other specific ideas. It looks like your code could be mixing sync and async contexts, but I'm unsure if that would cause this problem. Do you get any errors when testing live on a server?
Thanks for your help @MatthewFlamm.
Do you get any errors when testing live on a server?
You mean installing on a actual HA server? On my dev HA container it works fine, no errors.
Do you know another component with multiple tests that perform a state update?
I tried to create all the event handlers async and await the async_update_ha_state
and the tests worked. But I can't use that since the library I use can't call async event handlers.
Weird that the tests fail but when trying it out it all works fine. For some reason using self.hass.async_add_job(self.async_update_ha_state)
in tests doesn't really work.
(Also tried self.hass.add_job
)
Sounds like you now know the problem and it doesn't sound like it is this library. I would check whether any built in tests help you in this.
It seems that when I have multiple entity tests that trigger a state update, the given
hass
object isn't working correctly. I get this for every test, except the first one:And it really is only the first one that works. When I remove the first test, the second test succeeds and the others still fail. Is this a known issue?
Here is the source: https://github.com/TECH7Fox/asterisk-hass-integration/blob/asterisk-ami/tests/test_sensors.py
I could set all the sensors in one test, but I rather have them separated since they effect each other.
Hope someone can help me with this. Anyway, thanks for this very useful package!