ensure AsyncIOMainLoop is registered in tests

This commit is contained in:
Min RK
2018-10-15 16:15:46 +02:00
parent d64853a6f5
commit f3c2a15e53
2 changed files with 8 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ Fixtures to add functionality or spawning behavior
# Copyright (c) Jupyter Development Team. # Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
import asyncio
from getpass import getuser from getpass import getuser
import logging import logging
import os import os
@@ -34,6 +35,7 @@ from pytest import fixture, raises
from subprocess import TimeoutExpired from subprocess import TimeoutExpired
from tornado import ioloop, gen from tornado import ioloop, gen
from tornado.httpclient import HTTPError from tornado.httpclient import HTTPError
from tornado.platform.asyncio import AsyncIOMainLoop
from unittest import mock from unittest import mock
from .. import orm from .. import orm
@@ -121,8 +123,13 @@ def db():
@fixture(scope='module') @fixture(scope='module')
def io_loop(request): def io_loop(request):
"""Same as pytest-tornado.io_loop, but re-scoped to module-level""" """Same as pytest-tornado.io_loop, but re-scoped to module-level"""
ioloop.IOLoop.configure(AsyncIOMainLoop)
aio_loop = asyncio.new_event_loop()
asyncio.set_event_loop(aio_loop)
io_loop = ioloop.IOLoop() io_loop = ioloop.IOLoop()
io_loop.make_current() io_loop.make_current()
assert asyncio.get_event_loop() is aio_loop
assert io_loop.asyncio_loop is aio_loop
def _close(): def _close():
io_loop.clear_current() io_loop.clear_current()

View File

@@ -392,6 +392,7 @@ class StubSingleUserSpawner(MockSpawner):
evt = threading.Event() evt = threading.Event()
print(args, env) print(args, env)
def _run(): def _run():
asyncio.set_event_loop(asyncio.new_event_loop())
io_loop = IOLoop() io_loop = IOLoop()
io_loop.make_current() io_loop.make_current()
io_loop.add_callback(lambda : evt.set()) io_loop.add_callback(lambda : evt.set())