def _tearDown(self):
''' Destroy the event loop '''
if asyncio.iscoroutinefunction(self.tearDown):
self.loop.run_until_complete(self.tearDown())
else:
self.tearDown()
if not isinstance(self.loop, asyncio.AbstractEventLoop):
raise Exception('Invalid event loop: ', self.loop)
if self.loop.is_running():
self.loop.stop()
self.loop.close()
del self.loop
asyncio.set_event_loop_policy(None)
asyncio.set_event_loop(None)
# By explicitly forcing a garbage collection here,
# the event loop will report any remaining sockets
# and coroutines left in the event loop which indicates
# that further cleanup actions should be implemented
# in the code under test.
gc.collect()
评论列表
文章目录