Recently some of our tests started to fail because there is no event loop for asyncio present during them. It was not the case before, so need to understand what is going on and fix it.
Example of log with failing tests:
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7efed8b56f40>
@pytest.fixture(autouse=True)
def semaphore_patch(monkeypatch):
monkeypatch.setattr(
"alws.utils.pulp_client.PULP_SEMAPHORE",
> asyncio.Semaphore(5),
)
tests/fixtures/pulp.py:30:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib64/python3.9/asyncio/locks.py:375: in __init__
self._loop = events.get_event_loop()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <asyncio.unix_events._UnixDefaultEventLoopPolicy object at 0x7efee7d5eaf0>
def get_event_loop(self):
"""Get the event loop for the current context.
Returns an instance of EventLoop or raises an exception.
"""
if (self._local._loop is None and
not self._local._set_called and
threading.current_thread() is threading.main_thread()):
self.set_event_loop(self.new_event_loop())
if self._local._loop is None:
> raise RuntimeError('There is no current event loop in thread %r.'
% threading.current_thread().name)
E RuntimeError: There is no current event loop in thread 'MainThread'.```
Recently some of our tests started to fail because there is no event loop for asyncio present during them. It was not the case before, so need to understand what is going on and fix it. Example of log with failing tests: