From f3c2a15e53b82c800c244cd28689fb755fc5ff0b Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 15 Oct 2018 16:15:46 +0200 Subject: [PATCH] ensure AsyncIOMainLoop is registered in tests --- jupyterhub/tests/conftest.py | 7 +++++++ jupyterhub/tests/mocking.py | 1 + 2 files changed, 8 insertions(+) diff --git a/jupyterhub/tests/conftest.py b/jupyterhub/tests/conftest.py index d7b5f2da..47d413da 100644 --- a/jupyterhub/tests/conftest.py +++ b/jupyterhub/tests/conftest.py @@ -27,6 +27,7 @@ Fixtures to add functionality or spawning behavior # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. +import asyncio from getpass import getuser import logging import os @@ -34,6 +35,7 @@ from pytest import fixture, raises from subprocess import TimeoutExpired from tornado import ioloop, gen from tornado.httpclient import HTTPError +from tornado.platform.asyncio import AsyncIOMainLoop from unittest import mock from .. import orm @@ -121,8 +123,13 @@ def db(): @fixture(scope='module') def io_loop(request): """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.make_current() + assert asyncio.get_event_loop() is aio_loop + assert io_loop.asyncio_loop is aio_loop def _close(): io_loop.clear_current() diff --git a/jupyterhub/tests/mocking.py b/jupyterhub/tests/mocking.py index cba109ea..33ca7ebe 100644 --- a/jupyterhub/tests/mocking.py +++ b/jupyterhub/tests/mocking.py @@ -392,6 +392,7 @@ class StubSingleUserSpawner(MockSpawner): evt = threading.Event() print(args, env) def _run(): + asyncio.set_event_loop(asyncio.new_event_loop()) io_loop = IOLoop() io_loop.make_current() io_loop.add_callback(lambda : evt.set())