how to clean up between each test to prevent RuntimeError: Event loop is closed #384
-
Hi, I have an issue, with some code. I am importing a client from a separate file since it's basically a global dependency. Between individual pytest functions, it seems to use the client from the previous function. I am not a python pro, but I assume the client sticks around in some kind of import the import table. I have seen to some time ago with a different package as well actually. I am looking for a way to tear down everything and clear every module that may still stick around. You can see the issue in action in this example project. https://github.com/nbraun-wolf/async-mqtt-fastapi-pytest. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
You need to tie the client creation and shutdown to the application or test life cycle, just like you do with the HTTP client. Creating an async client as an import side effect is not going to work very well. |
Beta Was this translation helpful? Give feedback.
You need to tie the client creation and shutdown to the application or test life cycle, just like you do with the HTTP client. Creating an async client as an import side effect is not going to work very well.