Issue
While implement Python unittest by subclassing IsolatedAsyncioTestCase, it only runs first test case successfully. For any subsequent test case it throws error that event loop is closed. This happens in both Windows and Mac. Could you please suggest how to make sure that event loop is running during the execution of test within each of the subsclasses of the IsolatedAsyncioTestCase that I have implemented.
Solution
I had the same problem when trying to run integration tests. The first test passed, but the second one got an "Event loop is closed" error. I'm using MognoDB with the async driver. The reason for this error was the way the database connection was opened. IsolatedAsyncioTestCase creates a new event loop at the start and closes it at the end for execution.
So, a driver connection was attached to the event loop of the first TestCase, and when the second TestCase starts, it throws an error because the event loop of the first TestCase is already closed, but the new connection in the new event loop is not created.
The solution is to create a new database connection in each IsolatedAsyncioTestCase.
Answered By - Vitaliy Grusha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.