From 7b7f12c561d2404f92f0d494abc0174c5c7f5eeb Mon Sep 17 00:00:00 2001 From: Nickolai Novik Date: Thu, 8 Sep 2016 23:02:22 +0300 Subject: [PATCH] add uvloop to the test suite --- .travis.yml | 3 +++ tests/conftest.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fd2cffaa..99fedd9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,9 @@ before_script: - "mysql -e 'DROP DATABASE IF EXISTS test_pymysql2; create database test_pymysql2 DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;'" install: + - if python -c "import sys; sys.exit(sys.version_info < (3,5))"; then + pip install uvloop; + fi - pip install -Ur requirements-dev.txt - pip install . - pip install coveralls diff --git a/tests/conftest.py b/tests/conftest.py index 4ea28e22..a2df11f4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,11 +7,29 @@ import pytest +PY_35 = sys.version_info >= (3, 5) +if PY_35: + import uvloop +else: + uvloop = None + + +def pytest_generate_tests(metafunc): + if 'loop_type' in metafunc.fixturenames: + loop_type = ['asyncio', 'uvloop'] if uvloop else ['asyncio'] + metafunc.parametrize("loop_type", loop_type) + + @pytest.yield_fixture -def loop(request): +def loop(request, loop_type): loop = asyncio.new_event_loop() asyncio.set_event_loop(None) + if uvloop and loop_type == 'uvloop': + loop = uvloop.new_event_loop() + else: + loop = asyncio.new_event_loop() + yield loop if not loop._closed: