diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index 913af71c53e..db401fed64e 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -228,24 +228,24 @@ def new_func(self): @contextlib.contextmanager -def loop_context(): +def loop_context(loop_factory=asyncio.new_event_loop): """A contextmanager that creates an event_loop, for test purposes. Handles the creation and cleanup of a test loop. """ - loop = setup_test_loop() + loop = setup_test_loop(loop_factory) yield loop teardown_test_loop(loop) -def setup_test_loop(): +def setup_test_loop(loop_factory=asyncio.new_event_loop): """Create and return an asyncio.BaseEventLoop instance. The caller should also call teardown_test_loop, once they are done with the loop. """ - loop = asyncio.new_event_loop() + loop = loop_factory() asyncio.set_event_loop(None) return loop diff --git a/tests/test_web_sendfile_functional.py b/tests/test_web_sendfile_functional.py index 5289b49aeb1..10e6223e5ee 100644 --- a/tests/test_web_sendfile_functional.py +++ b/tests/test_web_sendfile_functional.py @@ -9,7 +9,7 @@ import aiohttp from aiohttp import log, request, web from aiohttp.file_sender import FileSender -from aiohttp.test_utils import unused_port +from aiohttp.test_utils import unused_port, loop_context try: import ssl @@ -17,6 +17,23 @@ ssl = False +try: + import uvloop +except: + uvloop = None + + +LOOP_FACTORIES = [asyncio.new_event_loop] +if uvloop: + LOOP_FACTORIES.append(uvloop.new_event_loop) + + +@pytest.yield_fixture(params=LOOP_FACTORIES) +def loop(request): + with loop_context(request.param) as loop: + yield loop + + @pytest.fixture(params=['sendfile', 'fallback'], ids=['sendfile', 'fallback']) def sender(request): def maker(*args, **kwargs):