Replies: 1 comment
-
@Ammadkhalid I can see that you're using a pytest fixture named loop, which provides an asyncio event loop to some of your fixtures. You're free to do this, but it won't work in combination with pytest-asyncio. Pytest-asyncio provides the same functionality with a fixture named event_loop. Combining both your loop fixture and pytest-asyncio's event_loop fixture will lead to issues, because there can only be one event loop at a time in any given thread. As a result, pytest-asyncio and your conftest.py will "compete" over who is in control of the asyncio event loop lifecycle. To solve this issue, I suggest replacing all occurrences of your loop fixture with event_loop. By default, the event_loop fixture has a function scope. If you need a wider fixture scope, there's a possibility to override the fixture as described in the docs: Does this information help? |
Beta Was this translation helpful? Give feedback.
-
@seifertm sorry for not providing information, I was creating video tutorial Setting Up Test Suits Using Pytest for a Tortoise ORM library and this is where i took advantage of this awesome Pytest plugin for asynchronous tests. I'm using this plugin version 0.21.0 However, i face the similar issue where event loop is being closed before fixture finalizer runs, https://github.com/Systembound/Just-FastApi_Tortoise-model-ORM-tests/blob/main/tests/conftest.py#L10
Originally reported by @Ammadkhalid here:
#30 (comment)
Beta Was this translation helpful? Give feedback.
All reactions