mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +00:00
ensure AsyncIOMainLoop is registered in tests
This commit is contained in:
@@ -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()
|
||||||
|
@@ -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())
|
||||||
|
Reference in New Issue
Block a user