-
Hello, Before:
After:
And
I understand that these set the the event loop for the test and the fixture to the same "session" loop. Without For example i have this file
Without Could you please point me back to the basic of pytest-asyncio? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
@jefflieu The concepts section of the pytest-asyncio documentation explains the idea of having event loops with different scopes. We're always open for suggestions to improve the documentation. Is there specific information that you're missing? Which pytest-asyncio version are you upgrading to? Side note about this piece of code:
In recent versions of pytest-asyncio, you can replace this section of the conftest.py with a simple setting. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Is it correct to say that
(I think part of my problem is that I never run an asyncio with multiple event loops) |
Beta Was this translation helpful? Give feedback.
-
Hi, Could you please also clarify these?
In version v1.0, from the concept page, I think I understand it as follows:
So, if these are all correct I think this is the critical difference between the 2 versions.
That leads to another question regarding "multiple event loops" running at the same time in the example I posted.
If I really want fixtures and tests running on different loops, what am I missing to make the example work? Thank you very much! Really appreciate you following and correcting my understanding. Jeff |
Beta Was this translation helpful? Give feedback.
-
any taker on this? are my questions valid or totally not making any sense (because I don't understand something) ?. |
Beta Was this translation helpful? Give feedback.
-
Sorry but your suggestion of having a fixture of scope package but loop_scope="function" doesn't work
My test code:
I'm a bit confused. I totally understand the concept of scope of fixture from pytest doc. |
Beta Was this translation helpful? Give feedback.
-
OK, it makes sense now. |
Beta Was this translation helpful? Give feedback.
Sorry, I forgot about this limitation.
The
scope
is the regular pytest scope that you're familiar with. I'll refer to it as caching scope. Theloop_scope
refers to the scope of the asyncio event loop. In other words, the loop scope decides when the event loop is reset.The loop scope can only be the same or a larger scope than the caching scope. It's impossible to cache the result of
test_fixture
for the whole test package (as specified byscope="package"
), if the loop is reset for every function (as specified byloop_scope="function"
).As a consequence, you either need to widen the loop scope of your fixture and test to
package
or you need to narrow the caching scope tofunction
.We shou…