From 889f8c571f11b2612b9cb0b78941c023bf41174c 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 | 5 +++-- tests/conftest.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index fd2cffaa..9094945d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,9 +31,10 @@ 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 script: - make cov 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: