ScopeMismatch: Overlap with pyetest-asyncio event_loop fixture
ididit4you opened this issue · 3 comments
Hello!
In pytest-asyncio there is event loop fixture with the same name but with function
scope.
Sometimes it works fine with your lib but in some cases, pytest-asyncio has a priority over your event_loop
fixture which causes an error about different scopes.
Something like this:
ScopeMismatch: You tried to access the 'function' scoped fixture 'event_loop' with a 'session' scoped request object, involved factories
../../../.pyenv/versions/3.9.5/envs/MyEnv/lib/python3.9/site-packages/pytest_asyncio/plugin.py:112: def wrapper(*args, **kwargs)
I faced this error when clone my own project which works fine to another machine and it starts spamming me with ScopeMismatch errors.
The only temporary solution which I can find is to create in my conftest.py
copy of your fixture with session
scope.
I will glad to provide more info and solution about this error, but it does not work only in the office computer, which impossible to access now.
Thanks for the report. I was aware of that, but didn't know of anyone using the lib 😄
I removed the event_loop
fixture from the plugin and added instructions to declare it on your own conftest.py
. Unfortunately, I couldn't find a better solution since we want to share the DB connection between tests and the pytest-asyncio event_loop
wouldn't allow that.
Let me know if that fixed for you.
Hello. Cool lib used as example for my setup. But I do have a noob question :P. I'm new to async, what is downsides in using session scoped event_loop
, how could it affect my tests?
There is no downside. It's how pytest-async
ask you to do.
It's just that at first I tried to define the event_loop
fixture in pytest-async-sqlachemy
itself so users would not have to bother with that. But as I explained in the docs, it didn't work because plugins can't override fixtures from one another.