-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about event loop changes using Redis/FakeRedis #622
Comments
Both stack traces complain about queues or tasks being attached to different event loops. Two things come to my mind:
As to why this occurs only from Python 3.10 onwards, I don't know. |
Thanks for comment. I'll have a look |
@M1ha-Shvn Any updates on your issue? |
I guess, my problem is a result of architecture: Redis storage connection object realises Singleton pattern. It creates single object and reuses Redis instance. For testing purposes it replaces Redis with FakeRedis. When tests are run each test is run in separate loop, but singleton object is still the same (as python thread is the same) which leads to loop changing problems when calling Redis commands. I've fixed the problem for myself by 2 things:
current_loop = asyncio.get_event_loop()
if self._loop is not None and self._loop is not current_loop:
self._redis_clients.clear()
# Script should be created in same loop, where it is executed
self._generate_worker_id_script = None
log('asyncio_loop_changed', 'asyncio_loop_changed', level=logging.WARNING)
self._loop = current_loop
@pytest.fixture(scope="session", autouse=True)
def event_loop() -> Generator["AbstractEventLoop", Any, None]:
policy = get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close() |
Maybe there's a smarter way for pytest-asyncio to detect loop changes. I'll leave the issue open for the time being. |
Faced the same problem when running tests locally |
It is interesting that the error is reproduced only when run tests module like |
I had the same issue. I was using Maybe this will help someone |
I tried it on version 5.0.0 – the error occurs. |
Hi.
I'm using fakeredis to run tests via pytest-asyncio in FastAPI application.
Library versions:
Everything works well in python 3.9 and earlier. But in 3.10 and 3.11 I start getting exceptions:
If I disable FakeRedis and use redis-py in tests without isolation, I start getting this error:
Firstly, I thought, it was a problem in Fakeredis and created an issue there. But now I suppose, that it is something connected with pytest-asyncio as:
Can you suggest anything and where to dig more?
Thanks
The text was updated successfully, but these errors were encountered: